- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / Z_DeleteInvoice.php
blobf5935aae88b6a08d9c4ad633fe6b7dcdbb268b7f
1 <?php
3 /* $Revision: 1.10 $ */
5 /* Script to delete an invoice expects and invoice number to delete
6 not included on any menu for obvious reasons
7 This page must be called directly using path/Z_DeleteInvoice.php?InvoiceNo=????? !! */
9 $PageSecurity=15;
11 include ('includes/session.inc');
12 $title = _('Delete Invoice');
13 include('includes/header.inc');
15 if (!isset($_GET['InvoiceNo'])){
16 prnMsg(_('This page must be called with the InvoiceNo to delete Z_DeleteInvoice.php?InvoiceNo=XX') . '. ' . _('This page should not be run by non-system administrators'),'info');
17 include('includes/footer.inc');
18 exit;
20 /*Get the order number that was invoiced */
22 $SQL = 'SELECT order_
23 FROM debtortrans
24 WHERE type = 10 and transno = ' . $_GET['InvoiceNo'];
26 $Result = DB_query($SQL,$db);
27 $myrow = DB_fetch_row($Result);
29 $ProcessingOrder = $myrow[0];
31 /*Now get the stock movements that were invoiced into an array */
33 $SQL = 'SELECT stockid,
34 loccode,
35 bundle,
36 debtorno,
37 branchcode,
38 prd,
39 qty,
40 mbflag
41 FROM stockmoves INNER JOIN stockmaster
42 ON stockmoves.stockid = stockmaster.stockid
43 WHERE transno =' .$_GET['InvoiceNo'] . ' AND type=10';
45 $Result = DB_query($SQL,$db);
47 $i=0;
49 While ($myrow = DB_fetch_array($Result)){
50 $StockMovement[$i] = $myrow;
51 $i++;
54 prnMsg(_('The number of stock movements to be deleted is') . ': ' . DB_num_rows($Result),'info');
56 /*Setup a database transaction */
57 $result = DB_query('BEGIN',$db);
59 /*Delete any log entries */
61 $SQL = 'DELETE FROM orderdeliverydifferenceslog
62 WHERE orderno = '. $ProcessingOrder . '
63 AND invoiceno = ' . $_GET['InvoiceNo'];
65 $ErrMsg = _('The SQL to delete the delivery differences records failed because');
66 $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
67 prnMsg(_('Any order delivery differences records have been deleted'),'info');
69 /*Now delete the DebtorTrans */
71 $SQL = 'DELETE FROM debtortrans
72 WHERE transno =' . $_GET['InvoiceNo'] . '
73 AND type=10';
74 $DbgMsg = _('The SQL that failed was');
75 $ErrMsg = _('The debtorTrans record could not be deleted') . ' - ' . _('the sql server returned the following error');
76 $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
78 prnMsg(_('The debtor transaction record has been deleted'),'info');
81 /*Now reverse updated SalesOrderDetails for the quantities invoiced and the actual dispatch dates. */
83 foreach ($StockMovement as $OrderLine) {
85 $SQL = 'UPDATE salesorderdetails SET qtyinvoiced = qtyinvoiced - ' . $OrderLine['qty'] . ',
86 completed = 0
87 WHERE orderno = ' . $ProcessingOrder . "
88 AND stkcode = '" . $OrderLine['stockid'] . "'";
90 $ErrMsg = _('The SQL to reverse the update of the sales order detail records failed because');
91 $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
92 prnMsg(_('The sales order records have been updated as not invoiced'),'info');
93 /*reverse the update to LocStock */
94 if ($OrderLine['mbflag']!='A' AND $OrderLine['mbflag']!='D'){
96 $ErrMsg = _('The SQL to reverse update to the location stock records failed because');
98 $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
99 prnMsg(_('Reversed the location stock quantities for items that decreased'),'info');
102 /*This is a problem - should only update sales analysis what happens where there
103 have been previous sales to the same customer/branch for the same item
104 Delete Sales Analysis records */
105 $SQL = 'DELETE FROM salesanalysis
106 WHERE periodno = ' . $OrderLine['prd'] . "
107 AND cust='" . $OrderLine['debtorno'] . "'
108 AND custbranch = '" . $OrderLine['branchcode'] . "'
109 AND qty = " . $OrderLine['qty'] . "
110 AND stockid = '" . $OrderLine['stockid'] . "'";
112 $ErrMsg = _('The SQL to delete the sales analysis records failed because');
114 $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg,true);
115 prnMsg(_('Sales analysis records deleted') . ' - ' . _('this deleted all sales analysis for the customer/branch and items on this invoice'),'info');
118 /* Delete the stock movements */
119 $SQL = 'DELETE FROM stockmoves WHERE type=10 AND transno = ' . $_GET['InvoiceNo'];
121 $ErrMsg = _('The SQL to delete the stock movement records failed because');
122 $Result = DB_query($SQL, $db,$ErrMsg,$DbgMsg,true);
123 prnMsg(_('The stock movement records associated with the invoice have been deleted'),'info');
124 echo '<BR><BR>';
125 prnMsg(_('Invoice number') . ' ' . $_GET['InvoiceNo'] . ' ' . _('has been deleted'),'info');
126 /* Delete any GL Transaction records*/
127 include('includes/footer.inc');