![]() |
Sergey Kornilov admin 5/10/2023 |
Instead of :journal_id you need to use $journal_id |
D
|
DRCR Dev author 5/11/2023 |
Thank you !!!!!! I didn't realise we could do that with this API. $rs = DB::Query("select year, period from current_period where user_id= ".$ID); // Delete allocations $rs3 = DB::Query("SELECT allocation_id FROM ledger WHERE journal_id = '".$journal_id."' AND user_id = ".$ID); foreach ($data3 as $row3) { // Reverse journal and use reversing code as journal_type $set = DB::PrepareSQL(" $sql = DB::PrepareSQL("INSERT INTO ledger ( // End Reverse journal and use reversing code as journal_type // Reverse customer invoices $set2 = DB::PrepareSQL("SET @journal_id2 = '$journal_id'; $sql2 = DB::PrepareSQL("INSERT INTO try{ DB::Exec ("START TRANSACTION;"); }catch (Exception $e) { DB::Exec ("ROLLBACK;"); //End Post Transaction` |
D
|
DRCR Dev author 5/11/2023 |
This is weird. The $sql and $sql2 print perfect MYSQL code that does exactly as expected in mysql, but the DB::Exec( $sql ); and DB::Exec( $sql2 ); lines do not run. $rs = DB::Query("select year, period from current_period where user_id= ".$ID); // Delete allocations $rs3 = DB::Query("SELECT allocation_id FROM ledger WHERE journal_id = '".$journal_id."' AND user_id = ".$ID); foreach ($data3 as $row3) { // Reverse journal and use reversing code as journal_type $sql = DB::PrepareSQL(" DB::Exec( $sql ); // End Reverse journal and use reversing code as journal_type // Reverse customer invoices $sql2 = DB::PrepareSQL(" // End Reverse customer invoices // Test SQL parameters in MYSQL echo $sql; // End Test SQL parameters in MYSQL |
D
|
DRCR Dev author 5/11/2023 |
FINAL CODE THAT WORKS - TRANSACTIONS
|
D
|
DRCR Dev author 5/11/2023 |
Reposted code for easy reading $rs = DB::Query("select year, period from current_period where user_id= ".$ID); // Delete allocations $rs3 = DB::Query("SELECT allocation_id FROM ledger WHERE journal_id = '".$journal_id."' AND user_id = ".$ID); foreach ($data3 as $row3) { // Reverse journal and use reversing code as journal_type $set1 = DB::PrepareSQL("SET @financial_year = $current_year;"); $sql = DB::PrepareSQL("INSERT INTO ledger ( // End Reverse journal and use reversing code as journal_type // Reverse customer invoices $set21 = DB::PrepareSQL("SET @journal_id2 = '$journal_id';"); $sql2 = DB::PrepareSQL("INSERT INTO // End Reverse customer invoices // Test SQL parameters in MYSQL echo $set1; // Run Transaction DB::Exec ("START TRANSACTION;"); try{ DB::Exec( $set1 ); DB::Exec( $set21 ); DB::Exec ("COMMIT;"); }catch (Exception $e) { DB::Exec ("ROLLBACK;"); |