From: <dai...@us...> - 2011-01-11 08:58:16
|
Revision: 4464 http://web-erp.svn.sourceforge.net/web-erp/?rev=4464&view=rev Author: daintree Date: 2011-01-11 08:58:07 +0000 (Tue, 11 Jan 2011) Log Message: ----------- fix up of purch orders/reciving etc Modified Paths: -------------- trunk/CustomerInquiry.php trunk/GoodsReceived.php trunk/PO_Items.php trunk/PO_PDFPurchOrder.php trunk/PO_SelectOSPurchOrder.php trunk/PrintCustTrans.php trunk/PrintCustTransPortrait.php trunk/SupplierCredit.php trunk/SupplierInvoice.php trunk/companies/weberpdemo/FormDesigns/SalesInvoice.xml trunk/doc/Change.log.html trunk/includes/DefinePOClass.php trunk/includes/PDFTransPageHeader.inc trunk/includes/PDFTransPageHeaderPortrait.inc trunk/includes/PO_ReadInOrder.inc Modified: trunk/CustomerInquiry.php =================================================================== --- trunk/CustomerInquiry.php 2011-01-10 21:30:27 UTC (rev 4463) +++ trunk/CustomerInquiry.php 2011-01-11 08:58:07 UTC (rev 4464) @@ -15,7 +15,7 @@ if(!isset($_GET['CustomerID']) AND !isset($_SESSION['CustomerID'])){ prnMsg(_('To display the enquiry a customer must first be selected from the customer selection screen'),'info'); - echo "<br><div class='centre'><a href='". $rootpath . "/SelectCustomer.php?" . SID . "'>" . _('Select a Customer to Inquire On') . '</a><br></div>'; + echo '<br><div class="centre"><a href="'. $rootpath . '/SelectCustomer.php?' . SID . '">' . _('Select a Customer to Inquire On') . '</a><br></div>'; include('includes/footer.inc'); exit; } else { @@ -185,26 +185,25 @@ echo '<table class="selection" cellpadding="2" colspan="7">'; -$tableheader = "<tr bgcolor =#800000> - <th>" . _('Type') . "</th> - <th>" . _('Number') . "</th> - <th>" . _('Date') . "</th> - <th>" . _('Branch') . "</th> - <th>" . _('Reference') . "</th> - <th>" . _('Comments') . "</th> - <th>" . _('Order') . "</th> - <th>" . _('Total') . "</th> - <th>" . _('Allocated') . "</th> - <th>" . _('Balance') . "</th> - <th>" . _('More Info') . "</th> - <th>" . _('More Info') . "</th> - <th>" . _('More Info') . "</th> - <th>" . _('More Info') . "</th> - <th>" . _('More Info') . "</th></tr>"; +$tableheader = '<tr> + <th>' . _('Type') . '</th> + <th>' . _('Number') . '</th> + <th>' . _('Date') . '</th> + <th>' . _('Branch') . '</th> + <th>' . _('Reference') . '</th> + <th>' . _('Comments') . '</th> + <th>' . _('Order') . '</th> + <th>' . _('Total') . '</th> + <th>' . _('Allocated') . '</th> + <th>' . _('Balance') . '</th> + <th>' . _('More Info') . '</th> + <th>' . _('More Info') . '</th> + <th>' . _('More Info') . '</th> + <th>' . _('More Info') . '</th> + <th>' . _('More Info') . '</th></tr>'; echo $tableheader; - $j = 1; $k=0; //row colour counter while ($myrow=DB_fetch_array($TransResult)) { @@ -218,33 +217,47 @@ } $FormatedTranDate = ConvertSQLDate($myrow['trandate']); + + if ($_SESSION['InvoicePortraitFormat']==1){ //Invoice/credits in portrait + $PrintCustomerTransactionScript = 'PrintCustTransPortrait.php'; + } else { //produce pdfs in landscape + $PrintCustomerTransactionScript = 'PrintCustTrans.php'; + } + + $BaseFormatString = '<td>%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + <td width="200">%s</td> + <td>%s</td> + <td class=number>%s</td> + <td class=number>%s</td> + <td class=number>%s</td>'; - $base_formatstr = "<td>%s</td> - <td>%s</td> - <td>%s</td> - <td>%s</td> - <td>%s</td> - <td width='200'>%s</td> - <td>%s</td> - <td class=number>%s</td> - <td class=number>%s</td> - <td class=number>%s</td>"; - $credit_invoice_str = "<td><a href='%s/Credit_Invoice.php?InvoiceNumber=%s'>" . _('Credit ') ."<IMG SRC='%s/credit.gif' title='" . _('Click to credit the invoice') . "'></a></td>"; -$preview_invoice_str = "<td><a href='%s/PrintCustTrans.php?FromTransNo=%s&InvOrCredit=Invoice'>" . _('HTML ') . "<IMG SRC='%s/preview.gif' title='" . _('Click to preview the invoice') . "'></a></td> -<td><a href='%s/PrintCustTransPortrait.php?FromTransNo=%s&InvOrCredit=Invoice&PrintPDF=True'>" . _('PDF ') . "<IMG SRC='%s/pdf.png' title='" . _('Click for PDF') . "'></a></td> - <td><a href='%s/EmailCustTrans.php?FromTransNo=%s&InvOrCredit=Invoice'>" . _('Email ') . "<IMG SRC='%s/email.gif' title='" . _('Click to email the invoice') . "'></a></td>"; - $preview_credit_str = "<td><a href='%s/PrintCustTrans.php?FromTransNo=%s&InvOrCredit=Credit'>" . _('HTML ') . " <IMG SRC='%s/preview.gif' title='" . _('Click to preview the credit note') . "'></a></td> -<td><a href='" .$rootpath."/PrintCustTransPortrait.php?FromTransNo=%s&InvOrCredit=Credit&PrintPDF=True'>" . _('PDF ') . "<IMG SRC='" .$rootpath."/css/".$theme."/images/pdf.png' title='" . _('Click for PDF') . "'></a></td> - <td><a href='%s/EmailCustTrans.php?FromTransNo=%s&InvOrCredit=Credit'>" . _('Email') . " <IMG SRC='%s/email.gif' title='" . _('Click to email the credit note') . "'></a></td>"; + $CreditInvoiceFormatString = '<td><a href="%s/Credit_Invoice.php?InvoiceNumber=%s">' . _('Credit ') .'<IMG SRC="%s/credit.gif" title="' . _('Click to credit the invoice') . '"></a></td>'; + + $PreviewInvoiceFormatString = '<td><a href="%s/PrintCustTrans.php?FromTransNo=%s&InvOrCredit=Invoice">' . _('HTML ') . '<IMG SRC="%s/preview.gif" title="' . _('Click to preview the invoice') . '"></a></td> + <td><a href="%s/%s?FromTransNo=%s&InvOrCredit=Invoice&PrintPDF=True">' . _('PDF ') . '<IMG SRC="%s/css/' . $theme . '/images/pdf.png" title="' . _('Click for PDF') . '"></a></td> + <td><a href="%s/EmailCustTrans.php?FromTransNo=%s&InvOrCredit=Invoice">' . _('Email ') . '<IMG SRC="%s/email.gif" title="' . _('Click to email the invoice') . '"></a></td>'; + + $PreviewCreditFormatString = '<td><a href="%s/PrintCustTrans.php?FromTransNo=%s&InvOrCredit=Credit">' . _('HTML ') . ' <IMG SRC="%s/preview.gif" title="' . _('Click to preview the credit note') . '"></a></td> + <td><a href="%s/%s?FromTransNo=%s&InvOrCredit=Credit&PrintPDF=True">' . _('PDF ') . '<IMG SRC="%s/css/' . $theme . '/images/pdf.png" title="' . _('Click for PDF') . '"></a></td> + <td><a href="%s/EmailCustTrans.php?FromTransNo=%s&InvOrCredit=Credit">' . _('Email') . ' <IMG SRC="%s/email.gif" title="' . _('Click to email the credit note') . '"></a></td>'; - if (in_array(3,$_SESSION['AllowedPageSecurityTokens']) && $myrow['type']==10){ /*Show a link to allow an invoice to be credited */ + /* assumed allowed page security token 3 allows the user to create credits for invoices */ + if (in_array(3,$_SESSION['AllowedPageSecurityTokens']) && $myrow['type']==10){ + /*Show a link to allow an invoice to be credited */ + /* assumed allowed page security token 8 allows the user to see GL transaction information */ if ($_SESSION['CompanyRecord']['gllink_debtors']== 1 AND in_array(8,$_SESSION['AllowedPageSecurityTokens'])){ - printf($base_formatstr . - $credit_invoice_str . - $preview_invoice_str . - "<td><a href='%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s'>" . _('View GL Entries') . " <IMG SRC='" .$rootpath."/css/".$theme."/images/gl.png' title='" . _('View the GL Entries') . "'></a></td> - </tr>", + + /* format string with GL inquiry options and for invoice to be credited */ + + printf($BaseFormatString . $CreditInvoiceFormatString . $PreviewInvoiceFormatString . + '<td><a href="%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s">' . _('View GL Entries') . ' <IMG SRC="' .$rootpath. '/css/'.$theme.'/images/gl.png" title="' . _('View the GL Entries') . '"></a></td> + </tr>', + //$BaseFormatString parameters $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), @@ -255,27 +268,30 @@ number_format($myrow['totalamount'],2), number_format($myrow['allocated'],2), number_format($myrow['totalamount']-$myrow['allocated'],2), + //$CreditInvoiceFormatString parameters $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', + //$PreviewInvoiceFormatString parameters $rootpath, - $myrow['transno'], - $rootpath.'/css/'.$theme.'/images', + $myrow['transno'], + $rootpath.'/css/'.$theme.'/images', $rootpath, + $PrintCustomerTransactionScript, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', + //Parameter for string for GL Trans Inquiries $rootpath, SID, $myrow['type'], $myrow['transno']); - } else { - printf($base_formatstr . - $credit_invoice_str . - $preview_invoice_str . - '</tr>', + } else { //user does not have privileges to see GL inquiry stuff + + printf($BaseFormatString . $CreditInvoiceFormatString . $PreviewInvoiceFormatString . '</tr>', + //BaseFormatString parameters $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), @@ -286,10 +302,17 @@ number_format($myrow['totalamount'],2), number_format($myrow['allocated'],2), number_format($myrow['totalamount']-$myrow['allocated'],2), + //CreditInvoiceFormatString parameters $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', - $rootpath, $myrow['transno'], + //$PreviewInvoiceFormatString parameters + $rootpath, + $myrow['transno'], + $rootpath.'/css/'.$theme.'/images', + $rootpath, + $PrintCustomerTransactionScript, + $myrow['transno'], $rootpath.'/css/'.$theme.'/images', $rootpath, $myrow['transno'], @@ -298,35 +321,39 @@ } elseif($myrow['type']==10) { /*its an invoice but not high enough priveliges to credit it */ - printf($base_formatstr . - $preview_invoice_str . + printf($BaseFormatString . + $PreviewInvoiceFormatString . '</tr>', + //$BaseFormatString parameters $myrow['typename'], - $myrow['transno'], - ConvertSQLDate($myrow['trandate']), - $myrow['branchcode'], - $myrow['reference'], - $myrow['invtext'], - $myrow['order_'], - number_format($myrow['totalamount'],2), - number_format($myrow['allocated'],2), - number_format($myrow['totalamount']-$myrow['allocated'],2), - $rootpath, - $myrow['transno'], - $rootpath.'/css/'.$theme.'/images', - $rootpath, - $myrow['transno'], - $rootpath.'/css/'.$theme.'/images', - $rootpath, - $myrow['transno'], - $rootpath.'/css/'.$theme.'/images'); + $myrow['transno'], + ConvertSQLDate($myrow['trandate']), + $myrow['branchcode'], + $myrow['reference'], + $myrow['invtext'], + $myrow['order_'], + number_format($myrow['totalamount'],2), + number_format($myrow['allocated'],2), + number_format($myrow['totalamount']-$myrow['allocated'],2), + //$PreviewInvoiceFormatString parameters + $rootpath, + $myrow['transno'], + $rootpath.'/css/'.$theme.'/images', + $rootpath, + $PrintCustomerTransactionScript, + $myrow['transno'], + $rootpath.'/css/'.$theme.'/images', + $rootpath, + $myrow['transno'], + $rootpath.'/css/'.$theme.'/images'); } elseif ($myrow['type']==11) { /*its a credit note */ if ($_SESSION['CompanyRecord']['gllink_debtors']== 1 AND in_array(8,$_SESSION['AllowedPageSecurityTokens'])){ - printf($base_formatstr . - $preview_credit_str . + printf($BaseFormatString . + $PreviewCreditFormatString . "<td><a href='%s/CustomerAllocations.php?AllocTrans=%s'>" . _('Allocation') . "<IMG SRC='" .$rootpath."/css/".$theme."/images/allocation.png' title='" . _('Click to allocate funds') . "'></a></td> <td><a href='%s/GLTransInquiry.php?%sTypeID=%s&TransNo=%s'>" . _('View GL Entries') . ' <a><IMG SRC="' .$rootpath.'/css/'.$theme.'/images/gl.png" title="' . _('View the GL Entries') . '"></a></td></tr>', + //$BaseFormatString parameters $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), @@ -337,13 +364,18 @@ number_format($myrow['totalamount'],2), number_format($myrow['allocated'],2), number_format($myrow['totalamount']-$myrow['allocated'],2), + //$PreviewCreditFormatString parameters $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', + $rootpath, + $PrintCustomerTransactionScript, $myrow['transno'], + $rootpath.'/css/'.$theme.'/images', $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', + // hand coded format string for Allocations and GLTrans Inquiry parameters $rootpath, $myrow['id'], $rootpath, @@ -351,8 +383,8 @@ $myrow['type'], $myrow['transno']); } else { - printf($base_formatstr . - $preview_credit_str . + printf($BaseFormatString . + $PreviewCreditFormatString . "<td><a href='%s/CustomerAllocations.php?AllocTrans=%s'>" . _('Allocation') . "<IMG SRC='%s/allocation.png' title='" . _('Click to allocate funds') . "'></a></td> </tr>", $myrow['typename'], @@ -365,22 +397,27 @@ number_format($myrow['totalamount'],2), number_format($myrow['allocated'],2), number_format($myrow['totalamount']-$myrow['allocated'],2), + //$PreviewCreditFormatString parameters $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', $rootpath, - $myrow['transno'], - $rootpath.'/css/'.$theme.'/images', + $PrintCustomerTransactionScript, + $myrow['transno'], + $rootpath.'/css/'.$theme.'/images', $rootpath, $myrow['transno'], $rootpath.'/css/'.$theme.'/images', + //Parameters for hand coded string to show allocations $rootpath, $myrow['id'], $rootpath.'/css/'.$theme.'/images'); } } elseif ($myrow['type']==12 AND $myrow['totalamount']<0) { /*its a receipt which could have an allocation*/ + + //If security token 8 in the allowed page security tokens then assumed ok for GL trans inquiries if ($_SESSION['CompanyRecord']['gllink_debtors']== 1 AND in_array(8,$_SESSION['AllowedPageSecurityTokens'])){ - printf($base_formatstr . + printf($BaseFormatString . "<td><a href='%s/CustomerAllocations.php?AllocTrans=%s'>" . _('Allocation') . "<IMG SRC='" .$rootpath."/css/".$theme."/images/allocation.png' title='" . _('Click to allocate funds') . "'></a></td> <td><a href='%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s'>" . _('View GL Entries') . " <IMG SRC='" .$rootpath."/css/".$theme."/images/gl.png' title='" . _('View the GL Entries') . "'></a></td> </tr>", @@ -400,8 +437,8 @@ SID, $myrow['type'], $myrow['transno']); - } else { - printf($base_formatstr . + } else { //no permission for GLTrans Inquiries + printf($BaseFormatString . "<td><a href='%s/CustomerAllocations.php?AllocTrans=%s'>" . _('Allocation') . "<IMG SRC='" .$rootpath."/css/".$theme."/images/allocation.png' title='" . _('Click to allocate funds') . "'></a></td> </tr>", $myrow['typename'], @@ -418,9 +455,11 @@ $myrow['id']); } } elseif ($myrow['type']==12 AND $myrow['totalamount']>0) { /*its a negative receipt */ + + //If security token 8 in the allowed page security tokens then assumed ok for GL trans inquiries if ($_SESSION['CompanyRecord']['gllink_debtors']== 1 AND in_array(8,$_SESSION['AllowedPageSecurityTokens'])){ - printf($base_formatstr . - "<td><a href='%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s'>" . _('View GL Entries') . ' <a></td></tr>', + printf($BaseFormatString . + '<td><a href="%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s">' . _('View GL Entries') . ' <a></td></tr>', $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), @@ -435,8 +474,8 @@ SID, $myrow['type'], $myrow['transno']); - } else { - printf($base_formatstr . '<td></tr>', + } else { //no permission for GLTrans Inquiries + printf($BaseFormatString . '<td></tr>', $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), @@ -449,9 +488,10 @@ number_format($myrow['totalamount']-$myrow['allocated'],2)); } } else { + //If security token 8 in the allowed page security tokens then assumed ok for GL trans inquiries if ($_SESSION['CompanyRecord']['gllink_debtors']== 1 AND in_array(8,$_SESSION['AllowedPageSecurityTokens'])){ - printf($base_formatstr . - "<td><a href='%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s'>" . _('View GL Entries') . ' <a></td></tr>', + printf($BaseFormatString . + '<td><a href="%s/GLTransInquiry.php?%s&TypeID=%s&TransNo=%s">' . _('View GL Entries') . ' <a></td></tr>', $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), @@ -467,7 +507,7 @@ $myrow['type'], $myrow['transno']); } else { - printf($base_formatstr . '</tr>', + printf($BaseFormatString . '</tr>', $myrow['typename'], $myrow['transno'], ConvertSQLDate($myrow['trandate']), Modified: trunk/GoodsReceived.php =================================================================== --- trunk/GoodsReceived.php 2011-01-10 21:30:27 UTC (rev 4463) +++ trunk/GoodsReceived.php 2011-01-11 08:58:07 UTC (rev 4464) @@ -4,22 +4,31 @@ /* $Revision: 1.44 $ */ -//$PageSecurity = 11; +//$PageSecurity = 11; now stored in the database /* Session started in header.inc for password checking and authorisation level check */ include('includes/DefinePOClass.php'); include('includes/DefineSerialItems.php'); include('includes/session.inc'); include('includes/SQL_CommonFunctions.inc'); -if (empty($identifier)) { - $identifier=''; + +/*The identifier makes this goods received session unique so cannot get confused + * with other sessions of goods received on the same machine/browser + * The identifier only needs to be unique for this php session, so a + * unix timestamp will be sufficient. + */ + +if (empty($_GET['identifier'])) { + $identifier=date('U'); +} else { + $identifier=$_GET['identifier']; } $title = _('Receive Purchase Orders'); include('includes/header.inc'); echo '<a href="'. $rootpath . '/PO_SelectOSPurchOrder.php?' . SID . '">' . _('Back to Purchase Orders'). '</a><br>'; -if (isset($_GET['PONumber']) and $_GET['PONumber']<=0 and !isset($_SESSION['PO'])) { +if (isset($_GET['PONumber']) and $_GET['PONumber']<=0 and !isset($_SESSION['PO'.$identifier])) { /* This page can only be called with a purchase order number for invoicing*/ echo '<div class="centre"><a href= "' . $rootpath . '/PO_SelectOSPurchOrder.php?' . SID . '">'. _('Select a purchase order to receive').'</a></div>'; @@ -34,37 +43,31 @@ } elseif (isset($_POST['Update']) OR isset($_POST['ProcessGoodsReceived'])) { /* if update quantities button is hit page has been called and ${$Line->LineNo} would have be - set from the post to the quantity to be received in this receival*/ + set from the post to the quantity to be received */ - foreach ($_SESSION['PO']->LineItems as $Line) { + foreach ($_SESSION['PO'.$identifier]->LineItems as $Line) { $RecvQty = $_POST['RecvQty_' . $Line->LineNo]; if (!is_numeric($RecvQty)){ $RecvQty = 0; } - $_SESSION['PO']->LineItems[$Line->LineNo]->ReceiveQty = $RecvQty; + $_SESSION['PO'.$identifier]->LineItems[$Line->LineNo]->ReceiveQty = $RecvQty; } } -$StatusSQL="SELECT status FROM purchorders WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; -$StatusResult=DB_query($StatusSQL, $db); -$StatusRow=DB_fetch_array($StatusResult); -$Status=$StatusRow['status']; - -if ($Status != PurchOrder::STATUS_PRINTED) { +if ($_SESSION['PO'.$identifier]->Status != 'Printed') { prnMsg( _('Purchase orders must have a status of Printed before they can be received').'.<br>'. - _('Order number') . ' ' . $_GET['PONumber'] . ' ' . _('has a status of') . ' ' . _($Status), 'warn'); + _('Order number') . ' ' . $_GET['PONumber'] . ' ' . _('has a status of') . ' ' . _($_SESSION['PO'.$identifier]->Status), 'warn'); include('includes/footer.inc'); exit; } /* Always display quantities received and recalc balance for all items on the order */ - echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Receive') . '" alt="" />' . ' ' . _('Receive Purchase Order') . ''; -echo ' : '. $_SESSION['PO']->OrderNo .' '. _('from'). ' ' . $_SESSION['PO']->SupplierName . '</p>'; -echo '<form action="' . $_SERVER['PHP_SELF'] . '?' . SID . '" method=post>'; +echo ' : '. $_SESSION['PO'.$identifier]->OrderNo .' '. _('from'). ' ' . $_SESSION['PO'.$identifier]->SupplierName . '</p>'; +echo '<form action="' . $_SERVER['PHP_SELF'] . '?' . SID . 'identifier=' . $identifier . '" method=post>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; if (!isset($_POST['ProcessGoodsReceived'])) { @@ -93,13 +96,14 @@ </tr>'; /*show the line items on the order with the quantity being received for modification */ - $_SESSION['PO']->Total = 0; + $_SESSION['PO'.$identifier]->Total = 0; } $k=0; //row colour counter -if (count($_SESSION['PO']->LineItems)>0 and !isset($_POST['ProcessGoodsReceived'])){ - foreach ($_SESSION['PO']->LineItems as $LnItm) { +if (count($_SESSION['PO'.$identifier]->LineItems)>0 and !isset($_POST['ProcessGoodsReceived'])){ + + foreach ($_SESSION['PO'.$identifier]->LineItems as $LnItm) { if ($k==1){ echo '<tr class="EvenTableRows">'; @@ -120,7 +124,7 @@ //Setup & Format values for LineItem display $LineTotal = ($LnItm->ReceiveQty * $LnItm->Price ); - $_SESSION['PO']->Total = $_SESSION['PO']->Total + $LineTotal; + $_SESSION['PO'.$identifier]->Total = $_SESSION['PO'.$identifier]->Total + $LineTotal; $DisplayQtyOrd = number_format($LnItm->Quantity,$LnItm->DecimalPlaces); $DisplayQtyRec = number_format($LnItm->QtyReceived,$LnItm->DecimalPlaces); $DisplayLineTotal = number_format($LineTotal,2); @@ -133,7 +137,7 @@ FROM purchdata LEFT JOIN unitsofmeasure ON purchdata.suppliersuom=unitsofmeasure.unitid - WHERE supplierno='".$_SESSION['PO']->SupplierID."' + WHERE supplierno='".$_SESSION['PO'.$identifier]->SupplierID."' AND stockid='".$LnItm->StockID."' GROUP BY unitsofmeasure.unitname"; @@ -185,7 +189,7 @@ echo '</tr>'; }//foreach(LineItem) echo "<script>defaultControl(document.forms[0].RecvQty_$LnItm->LineNo);</script>"; -$DisplayTotal = number_format($_SESSION['PO']->Total,2); +$DisplayTotal = number_format($_SESSION['PO'.$identifier]->Total,2); if ($_SESSION['ShowValueOnGRN']==1) { echo '<tr><td colspan=7 class=number><b>' . _('Total value of goods received'). '</b></td> <td class=number><b>'. $DisplayTotal. '</b></td> @@ -195,14 +199,6 @@ } }//If count(LineItems) > 0 -$SomethingReceived = 0; -if (count($_SESSION['PO']->LineItems)>0){ - foreach ($_SESSION['PO']->LineItems as $OrderLine) { - if ($OrderLine->ReceiveQty>0){ - $SomethingReceived =1; - } - } -} /************************* LINE ITEM VALIDATION ************************/ @@ -213,9 +209,9 @@ $NegativesFound = false; $InputError = false; -if (count($_SESSION['PO']->LineItems)>0){ +if (count($_SESSION['PO'.$identifier]->LineItems)>0){ - foreach ($_SESSION['PO']->LineItems as $OrderLine) { + foreach ($_SESSION['PO'.$identifier]->LineItems as $OrderLine) { if ($OrderLine->ReceiveQty+$OrderLine->QtyReceived > $OrderLine->Quantity * (1+ ($_SESSION['OverReceiveProportion'] / 100))){ $DeliveryQuantityTooLarge =1; @@ -225,7 +221,7 @@ $SQL = "SELECT locstock.quantity FROM locstock WHERE locstock.stockid='" . $OrderLine->StockID . "' - AND loccode= '" . $_SESSION['PO']->Location . "'"; + AND loccode= '" . $_SESSION['PO'.$identifier]->Location . "'"; $CheckNegResult = DB_query($SQL,$db); $CheckNegRow = DB_fetch_row($CheckNegResult); if ($CheckNegRow[0]+$OrderLine->ReceiveQty<0){ @@ -236,7 +232,7 @@ } /* end loop around the items received */ } /* end if there are lines received */ -if ($SomethingReceived==0 AND isset($_POST['ProcessGoodsReceived'])){ /*Then dont bother proceeding cos nothing to do ! */ +if ($_SESSION['PO'.$identifier]->SomethingReceived()==0 AND isset($_POST['ProcessGoodsReceived'])){ /*Then dont bother proceeding cos nothing to do ! */ prnMsg(_('There is nothing to process') . '. ' . _('Please enter valid quantities greater than zero'),'warn'); echo '<div class="centre"><input type=submit name=Update Value=' . _('Update') . '></div>'; @@ -254,7 +250,7 @@ prnMsg(_('Modify the ordered items on the purchase invoice if you wish to increase the quantities'),'info'); echo '<div class="centre"><input type=submit name=Update Value=' . _('Update') . '>'; -} elseif (isset($_POST['ProcessGoodsReceived']) AND $SomethingReceived==1 AND $InputError == false){ +} elseif (isset($_POST['ProcessGoodsReceived']) AND $_SESSION['PO'.$identifier]->SomethingReceived()==1 AND $InputError == false){ /* SQL to process the postings for goods received... */ /* Company record set at login for information on GL Links and debtors GL account*/ @@ -277,7 +273,7 @@ shiptref, jobref FROM purchorderdetails - WHERE orderno='" . (int) $_SESSION['PO']->OrderNo . "' + WHERE orderno='" . (int) $_SESSION['PO'.$identifier]->OrderNo . "' AND completed=0 ORDER BY podetailitem"; @@ -290,13 +286,13 @@ while ($myrow = DB_fetch_array($Result)) { - if ($_SESSION['PO']->LineItems[$LineNo]->GLCode != $myrow['glcode'] OR - $_SESSION['PO']->LineItems[$LineNo]->ShiptRef != $myrow['shiptref'] OR - $_SESSION['PO']->LineItems[$LineNo]->JobRef != $myrow['jobref'] OR - $_SESSION['PO']->LineItems[$LineNo]->QtyInv != $myrow['qtyinvoiced'] OR - $_SESSION['PO']->LineItems[$LineNo]->StockID != $myrow['itemcode'] OR - $_SESSION['PO']->LineItems[$LineNo]->Quantity != $myrow['quantityord'] OR - $_SESSION['PO']->LineItems[$LineNo]->QtyReceived != $myrow['quantityrecd']) { + if ($_SESSION['PO'.$identifier]->LineItems[$LineNo]->GLCode != $myrow['glcode'] OR + $_SESSION['PO'.$identifier]->LineItems[$LineNo]->ShiptRef != $myrow['shiptref'] OR + $_SESSION['PO'.$identifier]->LineItems[$LineNo]->JobRef != $myrow['jobref'] OR + $_SESSION['PO'.$identifier]->LineItems[$LineNo]->QtyInv != $myrow['qtyinvoiced'] OR + $_SESSION['PO'.$identifier]->LineItems[$LineNo]->StockID != $myrow['itemcode'] OR + $_SESSION['PO'.$identifier]->LineItems[$LineNo]->Quantity != $myrow['quantityord'] OR + $_SESSION['PO'.$identifier]->LineItems[$LineNo]->QtyReceived != $myrow['quantityrecd']) { prnMsg(_('This order has been changed or invoiced since this delivery was started to be actioned') . '. ' . _('Processing halted') . '. ' . _('To enter a delivery against this purchase order') . ', ' . _('it must be re-selected and re-read again to update the changes made by the other user'),'warn'); @@ -304,35 +300,35 @@ if ($debug==1){ echo '<table border=1>'; echo '<tr><td>' . _('GL Code of the Line Item') . ':</td> - <td>' . $_SESSION['PO']->LineItems[$LineNo]->GLCode . '</td> + <td>' . $_SESSION['PO'.$identifier]->LineItems[$LineNo]->GLCode . '</td> <td>' . $myrow['glcode'] . '</td></tr>'; echo '<tr><td>' . _('ShiptRef of the Line Item') . ':</td> - <td>' . $_SESSION['PO']->LineItems[$LineNo]->ShiptRef . '</td> + <td>' . $_SESSION['PO'.$identifier]->LineItems[$LineNo]->ShiptRef . '</td> <td>' . $myrow['shiptref'] . '</td></tr>'; echo '<tr><td>' . _('Contract Reference of the Line Item') . ':</td> - <td>' . $_SESSION['PO']->LineItems[$LineNo]->JobRef . '</td> + <td>' . $_SESSION['PO'.$identifier]->LineItems[$LineNo]->JobRef . '</td> <td>' . $myrow['jobref'] . '</td> </tr>'; echo '<tr><td>' . _('Quantity Invoiced of the Line Item') . ':</td> - <td>' . $_SESSION['PO']->LineItems[$LineNo]->QtyInv . '</td> + <td>' . $_SESSION['PO'.$identifier]->LineItems[$LineNo]->QtyInv . '</td> <td>' . $myrow['qtyinvoiced'] . '</td></tr>'; echo '<tr><td>' . _('Stock Code of the Line Item') . ':</td> - <td>'. $_SESSION['PO']->LineItems[$LineNo]->StockID . '</td> + <td>'. $_SESSION['PO'.$identifier]->LineItems[$LineNo]->StockID . '</td> <td>' . $myrow['itemcode'] . '</td></tr>'; echo '<tr><td>' . _('Order Quantity of the Line Item') . ':</td> - <td>' . $_SESSION['PO']->LineItems[$LineNo]->Quantity . '</td> + <td>' . $_SESSION['PO'.$identifier]->LineItems[$LineNo]->Quantity . '</td> <td>' . $myrow['quantityord'] . '</td></tr>'; echo '<tr><td>' . _('Quantity of the Line Item Already Received') . ':</td> - <td>' . $_SESSION['PO']->LineItems[$LineNo]->QtyReceived . '</td> + <td>' . $_SESSION['PO'.$identifier]->LineItems[$LineNo]->QtyReceived . '</td> <td>' . $myrow['quantityrecd'] . '</td></tr>'; echo '</table>'; } echo "<div class='centre'><a href='$rootpath/PO_SelectOSPurchOrder.php?" . SID . "'>". _('Select a different purchase order for receiving goods against').'</a></div>'; echo "<div class='centre'><a href='$rootpath/GoodsReceived.php?" . SID . '&PONumber=' . - $_SESSION['PO']->OrderNumber . '">'. _('Re-read the updated purchase order for receiving goods against'). '</a></div>'; - unset($_SESSION['PO']->LineItems); - unset($_SESSION['PO']); + $_SESSION['PO'.$identifier]->OrderNumber . '">'. _('Re-read the updated purchase order for receiving goods against'). '</a></div>'; + unset($_SESSION['PO'.$identifier]->LineItems); + unset($_SESSION['PO'.$identifier]); unset($_POST['ProcessGoodsReceived']); include ('includes/footer.inc'); exit; @@ -351,11 +347,11 @@ $PeriodNo = GetPeriod($_POST['DefaultReceivedDate'], $db); $_POST['DefaultReceivedDate'] = FormatDateForSQL($_POST['DefaultReceivedDate']); - foreach ($_SESSION['PO']->LineItems as $OrderLine) { + foreach ($_SESSION['PO'.$identifier]->LineItems as $OrderLine) { if ($OrderLine->ReceiveQty !=0 AND $OrderLine->ReceiveQty!='' AND isset($OrderLine->ReceiveQty)) { - $LocalCurrencyPrice = ($OrderLine->Price / $_SESSION['PO']->ExRate); + $LocalCurrencyPrice = ($OrderLine->Price / $_SESSION['PO'.$identifier]->ExRate); if ($OrderLine->StockID!='') { /*Its a stock item line */ /*Need to get the current standard cost as it is now so we can process GL jorunals later*/ @@ -369,23 +365,23 @@ $myrow = DB_fetch_row($Result); if ($OrderLine->QtyReceived==0){ //its the first receipt against this line - $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost = $myrow[0]; + $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = $myrow[0]; } $CurrentStandardCost = $myrow[0]; /*Set the purchase order line stdcostunit = weighted average / standard cost used for all receipts of this line This assures that the quantity received against the purchase order line multiplied by the weighted average of standard costs received = the total of standard cost posted to GRN suspense*/ - $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost = (($CurrentStandardCost * $OrderLine->ReceiveQty) + ($_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost *$OrderLine->QtyReceived)) / ($OrderLine->ReceiveQty + $OrderLine->QtyReceived); + $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = (($CurrentStandardCost * $OrderLine->ReceiveQty) + ($_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost *$OrderLine->QtyReceived)) / ($OrderLine->ReceiveQty + $OrderLine->QtyReceived); } elseif ($OrderLine->QtyReceived==0 AND $OrderLine->StockID=='') { /*Its a nominal item being received */ /*Need to record the value of the order per unit in the standard cost field to ensure GRN account entries clear */ - $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost = $LocalCurrencyPrice; + $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = $LocalCurrencyPrice; } if ($OrderLine->StockID=='') { /*Its a NOMINAL item line */ - $CurrentStandardCost = $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost; + $CurrentStandardCost = $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost; } /*Now the SQL to do the update to the PurchOrderDetails */ @@ -393,13 +389,13 @@ if ($OrderLine->ReceiveQty >= ($OrderLine->Quantity - $OrderLine->QtyReceived)){ $SQL = "UPDATE purchorderdetails SET quantityrecd = quantityrecd + '" . $OrderLine->ReceiveQty . "', - stdcostunit='" . $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost . "', + stdcostunit='" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "', completed=1 WHERE podetailitem = '" . $OrderLine->PODetailRec . "'"; } else { $SQL = "UPDATE purchorderdetails SET quantityrecd = quantityrecd + '" . $OrderLine->ReceiveQty . "', - stdcostunit='" . $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost . "', + stdcostunit='" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "', completed=0 WHERE podetailitem = '" . $OrderLine->PODetailRec . "'"; } @@ -412,7 +408,7 @@ if ($OrderLine->StockID !=''){ /*Its a stock item so use the standard cost for the journals */ $UnitCost = $CurrentStandardCost; } else { /*otherwise its a nominal PO item so use the purchase cost converted to local currency */ - $UnitCost = $OrderLine->Price / $_SESSION['PO']->ExRate; + $UnitCost = $OrderLine->Price / $_SESSION['PO'.$identifier]->ExRate; } /*Need to insert a GRN item */ @@ -431,7 +427,7 @@ '" . $OrderLine->ItemDescription . "', '" . $_POST['DefaultReceivedDate'] . "', '" . $OrderLine->ReceiveQty . "', - '" . $_SESSION['PO']->SupplierID . "', + '" . $_SESSION['PO'.$identifier]->SupplierID . "', '" . $CurrentStandardCost . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('A GRN record could not be inserted') . '. ' . _('This receipt of goods has not been processed because'); @@ -446,7 +442,7 @@ $SQL="SELECT locstock.quantity FROM locstock WHERE locstock.stockid='" . $OrderLine->StockID . "' - AND loccode= '" . $_SESSION['PO']->Location . "'"; + AND loccode= '" . $_SESSION['PO'.$identifier]->Location . "'"; $Result = DB_query($SQL, $db); if (DB_num_rows($Result)==1){ @@ -460,7 +456,7 @@ $SQL = "UPDATE locstock SET quantity = locstock.quantity + '" . $OrderLine->ReceiveQty . "' WHERE locstock.stockid = '" . $OrderLine->StockID . "' - AND loccode = '" . $_SESSION['PO']->Location . "'"; + AND loccode = '" . $_SESSION['PO'.$identifier]->Location . "'"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because'); $DbgMsg = _('The following SQL to update the location stock record was used'); @@ -483,13 +479,13 @@ '" . $OrderLine->StockID . "', 25, '" . $GRN . "', - '" . $_SESSION['PO']->Location . "', + '" . $_SESSION['PO'.$identifier]->Location . "', '" . $_POST['DefaultReceivedDate'] . "', '" . $LocalCurrencyPrice . "', '" . $PeriodNo . "', - '" . $_SESSION['PO']->SupplierID . " (" . $_SESSION['PO']->SupplierName . ") - " .$_SESSION['PO']->OrderNo . "', + '" . $_SESSION['PO'.$identifier]->SupplierID . " (" . $_SESSION['PO'.$identifier]->SupplierName . ") - " .$_SESSION['PO'.$identifier]->OrderNo . "', '" . $OrderLine->ReceiveQty . "', - '" . $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost . "', + '" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "', '" . ($QtyOnHandPrior + $OrderLine->ReceiveQty) . "' )"; @@ -509,7 +505,7 @@ //need to test if the controlled item exists first already $SQL = "SELECT COUNT(*) FROM stockserialitems WHERE stockid='" . $OrderLine->StockID . "' - AND loccode = '" . $_SESSION['PO']->Location . "' + AND loccode = '" . $_SESSION['PO'.$identifier]->Location . "' AND serialno = '" . $Item->BundleRef . "'"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Could not check if a batch or lot stock item already exists because'); $DbgMsg = _('The following SQL to test for an already existing controlled but not serialised stock item was used'); @@ -523,7 +519,7 @@ $SQL = "UPDATE stockserialitems SET quantity = quantity + '" . $Item->BundleQty . "'"; } $SQL .= "WHERE stockid='" . $OrderLine->StockID . "' - AND loccode = '" . $_SESSION['PO']->Location . "' + AND loccode = '" . $_SESSION['PO'.$identifier]->Location . "' AND serialno = '" . $Item->BundleRef . "'"; } else { $SQL = "INSERT INTO stockserialitems (stockid, @@ -532,7 +528,7 @@ qualitytext, quantity) VALUES ('" . $OrderLine->StockID . "', - '" . $_SESSION['PO']->Location . "', + '" . $_SESSION['PO'.$identifier]->Location . "', '" . $Item->BundleRef . "', '', '" . $Item->BundleQty . "')"; @@ -582,7 +578,7 @@ transdate, periodno, inputdate, - fixedassettranstype + fixedassettranstype, amount) VALUES ('" . $OrderLine->AssetID . "', 25, @@ -599,9 +595,12 @@ /*Now get the correct cost GL account from the asset category */ $AssetRow = DB_fetch_array($CheckAssetExistsResult); /*Over-ride any GL account specified in the order with the asset category cost account */ - $_SESSION['PO']->LineItems[$OrderLine->LineNo]->GLCode = $AssetRow['costact']; + $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->GLCode = $AssetRow['costact']; /*Now if there are no previous additions to this asset update the date purchased */ - if ($AssetRow['datepurchased']=='0000-00-00'){ + if ($AssetRow['datepurchased']=='0000-00-00'){ + /* it is a new addition as the date is set to 0000-00-00 when the asset record is created + * before any cost is added to the asset + */ $SQL = "UPDATE fixedassets SET datepurchased='" . $_POST['DefaultReceivedDate'] . "', cost = cost + " . ($CurrentStandardCost * $OrderLine->ReceiveQty) . " WHERE assetid = '" . $OrderLine->AssetID . "'"; @@ -615,11 +614,12 @@ } //assetid provided doesn't exist so ignore it and treat as a normal nominal item } //assetid is set so the nominal item is an asset -/* If GLLink_Stock then insert GLTrans to debit the GL Code and credit GRN Suspense account at standard cost*/ - if ($_SESSION['PO']->GLLink==1 AND $OrderLine->GLCode !=0){ /*GLCode is set to 0 when the GLLink is not activated this covers a situation where the GLLink is now active but it wasn't when this PO was entered */ + + /* If GLLink_Stock then insert GLTrans to debit the GL Code and credit GRN Suspense account at standard cost*/ + if ($_SESSION['PO'.$identifier]->GLLink==1 AND $OrderLine->GLCode !=0){ + /*GLCode is set to 0 when the GLLink is not activated this covers a situation where the GLLink is now active but it wasn't when this PO was entered */ -/*first the debit using the GLCode in the PO detail record entry*/ - + /*first the debit using the GLCode in the PO detail record entry*/ $SQL = "INSERT INTO gltrans (type, typeno, trandate, @@ -633,7 +633,7 @@ '" . $_POST['DefaultReceivedDate'] . "', '" . $PeriodNo . "', '" . $OrderLine->GLCode . "', - 'PO: " . $_SESSION['PO']->OrderNo . " " . $_SESSION['PO']->SupplierID . " - " . $OrderLine->StockID + 'PO: " . $_SESSION['PO'.$identifier]->OrderNo . " " . $_SESSION['PO'.$identifier]->SupplierID . " - " . $OrderLine->StockID . " - " . $OrderLine->ItemDescription . " x " . $OrderLine->ReceiveQty . " @ " . number_format($CurrentStandardCost,2) . "', '" . $CurrentStandardCost * $OrderLine->ReceiveQty . "' @@ -645,7 +645,7 @@ /* If the CurrentStandardCost != UnitCost (the standard at the time the first delivery was booked in, and its a stock item, then the difference needs to be booked in against the purchase price variance account */ - /*now the GRN suspense entry*/ + /*now the GRN suspense entry*/ $SQL = "INSERT INTO gltrans (type, typeno, trandate, @@ -658,7 +658,7 @@ '" . $_POST['DefaultReceivedDate'] . "', '" . $PeriodNo . "', '" . $_SESSION['CompanyRecord']['grnact'] . "', - '" . _('PO') . ': ' . $_SESSION['PO']->OrderNo . ' ' . $_SESSION['PO']->SupplierID . ' - ' . + '" . _('PO'.$identifier) . ': ' . $_SESSION['PO'.$identifier]->OrderNo . ' ' . $_SESSION['PO'.$identifier]->SupplierID . ' - ' . $OrderLine->StockID . ' - ' . $OrderLine->ItemDescription . ' x ' . $OrderLine->ReceiveQty . ' @ ' . number_format($UnitCost,2) . "', '" . -$UnitCost * $OrderLine->ReceiveQty . "' @@ -671,35 +671,23 @@ } /* end of if GL and stock integrated and standard cost !=0 */ } /*Quantity received is != 0 */ } /*end of OrderLine loop */ - $CompletedSQL="SELECT SUM(completed) as completedlines, - COUNT(podetailitem) as alllines - FROM purchorderdetails - WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; - $CompletedResult=DB_query($CompletedSQL,$db); - $MyCompletedRow=DB_fetch_array($CompletedResult); - $Status=$MyCompletedRow['alllines']-$MyCompletedRow['completedlines']; - - if ($Status==0) { - $sql="SELECT stat_comment - FROM purchorders - WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; - $result=DB_query($sql,$db); - $myrow=DB_fetch_array($result); - $comment=$myrow['stat_comment']; - $date = date($_SESSION['DefaultDateFormat']); - $StatusComment=$date.' - Order Completed'.'<br>'.$comment; + + + + if ($_SESSION['PO'.$identifier]->AllLinesReceived()==1) { //all lines on the purchase order are now completed + $StatusComment=date($_SESSION['DefaultDateFormat']) .' - ' . _('Order Completed') .'<br />' . $_SESSION['PO'.$identifier]->StatusComment; $sql="UPDATE purchorders - SET status='" . PurchOrder::STATUS_COMPLITED . "', + SET status='Completed', stat_comment='" . $StatusComment . "' - WHERE orderno='" . $_SESSION['PO']->OrderNo . "'"; + WHERE orderno='" . $_SESSION['PO'.$identifier]->OrderNo . "'"; $result=DB_query($sql,$db); } $Result = DB_Txn_Commit($db); - $PONo = $_SESSION['PO']->OrderNo; - unset($_SESSION['PO']->LineItems); - unset($_SESSION['PO']); + $PONo = $_SESSION['PO'.$identifier]->OrderNo; + unset($_SESSION['PO'.$identifier]->LineItems); + unset($_SESSION['PO'.$identifier]); unset($_POST['ProcessGoodsReceived']); echo '<br><div class=centre>'. _('GRN number'). ' '. $GRN .' '. _('has been processed').'<br>'; Modified: trunk/PO_Items.php =================================================================== --- trunk/PO_Items.php 2011-01-10 21:30:27 UTC (rev 4463) +++ trunk/PO_Items.php 2011-01-11 08:58:07 UTC (rev 4464) @@ -102,8 +102,7 @@ if ($_SESSION['ExistingOrder']==0){ /*its a new order to be inserted */ //Do we need to check authorisation to create - no because already trapped when new PO session started - $StatusComment=date($_SESSION['DefaultDateFormat']).' - ' . _('Order Created by') . ' <a href="mailto:'. $_SESSION['UserEmail'] .'">'.$_SESSION['PO'.$identifier]->Initiator. - '</a> - '.$_SESSION['PO'.$identifier]->StatusMessage.'<br>'; + $StatusComment=date($_SESSION['DefaultDateFormat']).' - ' . _('Order Created by') . ' <a href="mailto:'. $_SESSION['UserEmail'] .'">' . $_SESSION['PO'.$identifier]->Initiator . '</a> - '.$_SESSION['PO'.$identifier]->StatusMessage.'<br>'; /*Get the order number */ $_SESSION['PO'.$identifier]->OrderNo = GetNextTransNo(18, $db); Modified: trunk/PO_PDFPurchOrder.php =================================================================== --- trunk/PO_PDFPurchOrder.php 2011-01-10 21:30:27 UTC (rev 4463) +++ trunk/PO_PDFPurchOrder.php 2011-01-11 08:58:07 UTC (rev 4464) @@ -4,16 +4,25 @@ include('includes/session.inc'); include('includes/SQL_CommonFunctions.inc'); include('includes/DefinePOClass.php'); + if(!isset($_GET['OrderNo']) && !isset($_POST['OrderNo'])){ $title = _('Select a Purchase Order'); include('includes/header.inc'); echo '<div class="centre"><br><br><br>'; prnMsg( _('Select a Purchase Order Number to Print before calling this page') , 'error'); - echo '<br><br><br><table class="table_index"> - <tr><td class="menu_group_item"> - <li><a href="'. $rootpath . '/PO_SelectOSPurchOrder.php?'.SID .'">' . _('Outstanding Purchase Orders') . '</a></li> - <li><a href="'. $rootpath . '/PO_SelectPurchOrder.php?'. SID .'">' . _('Purchase Order Inquiry') . '</a></li> - </td></tr></table></div><br><br><br>'; + echo '<br /> + <br /> + <br /> + <table class="table_index"> + <tr><td class="menu_group_item"> + <li><a href="'. $rootpath . '/PO_SelectOSPurchOrder.php?'.SID .'">' . _('Outstanding Purchase Orders') . '</a></li> + <li><a href="'. $rootpath . '/PO_SelectPurchOrder.php?'. SID .'">' . _('Purchase Order Inquiry') . '</a></li> + </td> + </tr></table> + </div> + <br /> + <br /> + <br />'; include('includes/footer.inc'); exit(); @@ -29,10 +38,10 @@ $title = _('Print Purchase Order Number').' '. $OrderNo; /* If we are not previewing the order then find * the order status */ -if ($OrderNo != 'Preview') { +if ($OrderNo != 'Preview') { // then we are printing a real order $sql="SELECT status - FROM purchorders - WHERE orderno='".$OrderNo."'"; + FROM purchorders + WHERE orderno='".$OrderNo."'"; $result=DB_query($sql, $db); $myrow=DB_fetch_array($result); $OrderStatus=$myrow['status']; @@ -42,70 +51,81 @@ $OrderStatus = _('Printed'); $MakePDFThenDisplayIt = True; } -if ($OrderStatus != PurchOrder::STATUS_AUTHORISED and $OrderStatus != PurchOrder::STATUS_PRINTED) { +if ($OrderStatus != 'Authorised' AND $OrderStatus != 'Printed') { include('includes/header.inc'); prnMsg( _('Purchase orders can only be printed once they have been authorised') . '. ' . _('This order is currently at a status of') . ' ' . _($OrderStatus),'warn'); include('includes/footer.inc'); exit; } +if ($_POST['PrintOrEmail']=='Email' AND ! IsEmailAddress($_POST['EmailTo'])){ + include('includes/header.inc'); + prnMsg( _('The email address entered does not appear to be valid. No emails have been sent.'),'warn'); + include('includes/footer.inc'); + exit; +} $ViewingOnly = 0; -if (isset($_GET['ViewingOnly']) && $_GET['ViewingOnly']!='') { +if (isset($_GET['ViewingOnly']) AND $_GET['ViewingOnly']!='') { $ViewingOnly = $_GET['ViewingOnly']; -} elseif (isset($_POST['ViewingOnly']) && $_POST['ViewingOnly']!='') { +} elseif (isset($_POST['ViewingOnly']) AND $_POST['ViewingOnly']!='') { $ViewingOnly = $_POST['ViewingOnly']; } -/* If we are previewing the order then we dont - * want to email it */ -if ($OrderNo != 'Preview') { +/* If we are previewing the order then we dont want to email it */ +if ($OrderNo == 'Preview') { //OrderNo is set to 'Preview' when just looking at the format of the printed order $_POST['PrintOrEmail']='Print'; } -if (isset($_POST['DoIt']) AND ($_POST['PrintOrEmail']=='Print' || $ViewingOnly==1) ){ +if (isset($_POST['DoIt']) AND ($_POST['PrintOrEmail']=='Print' OR $ViewingOnly==1) ){ $MakePDFThenDisplayIt = True; -} elseif (isset($_POST['DoIt']) AND $_POST['PrintOrEmail']=='Email' AND strlen($_POST['EmailTo'])>6){ +} elseif (isset($_POST['DoIt']) AND $_POST['PrintOrEmail']=='Email'){ $MakePDFThenEmailIt = True; } -if (isset($OrderNo) && $OrderNo != "" && $OrderNo > 0 && $OrderNo != 'Preview'){ - //Check this up front. Note that the myrow recordset is carried into the actual make pdf section +if (isset($OrderNo) AND $OrderNo != '' AND $OrderNo > 0 AND $OrderNo != 'Preview'){ /*retrieve the order details from the database to print */ $ErrMsg = _('There was a problem retrieving the purchase order header details for Order Number'). ' ' . $OrderNo . ' ' . _('from the database'); - $sql = "SELECT - purchorders.supplierno, - suppliers.suppname, - suppliers.address1, - suppliers.address2, - suppliers.address3, - suppliers.address4, - purchorders.comments, - purchorders.orddate, - purchorders.rate, - purchorders.dateprinted, - purchorders.deladd1, - purchorders.deladd2, - purchorders.deladd3, - purchorders.deladd4, - purchorders.deladd5, - purchorders.deladd6, - purchorders.allowprint, - purchorders.requisitionno, - purchorders.initiator, - purchorders.paymentterms, - suppliers.currcode - FROM purchorders INNER JOIN suppliers - ON purchorders.supplierno = suppliers.supplierid - WHERE purchorders.orderno='" . $OrderNo ."'"; + $sql = "SELECT purchorders.supplierno, + suppliers.suppname, + suppliers.address1, + suppliers.address2, + suppliers.address3, + suppliers.address4, + purchorders.comments, + purchorders.orddate, + purchorders.rate, + purchorders.dateprinted, + purchorders.deladd1, + purchorders.deladd2, + purchorders.deladd3, + purchorders.deladd4, + purchorders.deladd5, + purchorders.deladd6, + purchorders.allowprint, + purchorders.requisitionno, + purchorders.initiator, + purchorders.paymentterms, + suppliers.currcode, + purchorders.status, + purchorders.stat_comment + FROM purchorders INNER JOIN suppliers + ON purchorders.supplierno = suppliers.supplierid + WHERE purchorders.orderno='" . $OrderNo ."'"; $result=DB_query($sql,$db, $ErrMsg); if (DB_num_rows($result)==0){ /*There is no order header returned */ $title = _('Print Purchase Order Error'); include('includes/header.inc'); echo '<div class="centre"><br><br><br>'; prnMsg( _('Unable to Locate Purchase Order Number') . ' : ' . $OrderNo . ' ', 'error'); - echo '<br><br><br><table class="table_index"> - <tr><td class="menu_group_item"> - <li><a href="'. $rootpath . '/PO_SelectOSPurchOrder.php?'.SID .'">' . _('Outstanding Purchase Orders') . '</a></li> - <li><a href="'. $rootpath . '/PO_SelectPurchOrder.php?'. SID .'">' . _('Purchase Order Inquiry') . '</a></li> - </td></tr></table></div><br><br><br>'; + echo '<br /> + <br /> + <br /> + <table class="table_index"> + <tr><td class="menu_group_item"> + <li><a href="'. $rootpath . '/PO_SelectOSPurchOrder.php?'.SID .'">' . _('Outstanding Purchase Orders') . '</a></li> + <li><a href="'. $rootpath . '/PO_SelectPurchOrder.php?'. SID .'">' . _('Purchase Order Inquiry') . '</a></li> + </td> + </tr> + </table> + </div><br><br><br>'; include('includes/footer.inc'); exit(); } elseif (DB_num_rows($result)==1){ /*There is only one order header returned */ @@ -115,8 +135,7 @@ $title = _('Purchase Order Already Printed'); include('includes/header.inc'); echo '<p>'; - prnMsg( _('Purchase Order Number').' ' . $OrderNo . ' '. - _('has previously been printed') . '. ' . _('It was printed on'). ' ' . + prnMsg( _('Purchase Order Number').' ' . $OrderNo . ' '. _('has previously been printed') . '. ' . _('It was printed on'). ' ' . ConvertSQLDate($POHeader['dateprinted']) . '<br>'. _('To re-print the order it must be modified to allow a reprint'). '<br>'. _('This check is there to ensure that duplicate purchase orders are not sent to the supplier resulting in several deliveries of the same supplies'), 'warn'); @@ -179,17 +198,17 @@ $ErrMsg = _('There was a problem retrieving the line details for order number') . ' ' . $OrderNo . ' ' . _('from the database'); $sql = "SELECT itemcode, - deliverydate, - itemdescription, - unitprice, - unitname as units, - quantityord, - decimalplaces - FROM purchorderdetails LEFT JOIN stockmaster - ON purchorderdetails.itemcode=stockmaster.stockid - LEFT JOIN unitsofmeasure - ON purchorderdetails.uom=unitsofmeasure.unitid - WHERE orderno ='" . $OrderNo ."'"; + deliverydate, + itemdescription, + unitprice, + unitname as units, + quantityord, + decimalplaces + FROM purchorderdetails LEFT JOIN stockmaster + ON purchorderdetails.itemcode=stockmaster.stockid + LEFT JOIN unitsofmeasure + ON purchorderdetails.uom=unitsofmeasure.unitid + WHERE orderno ='" . $OrderNo ."'"; $result=DB_query($sql,$db); } if ($OrderNo=='Preview' or DB_num_rows($result)>0){ @@ -213,22 +232,22 @@ if ($_POST['ShowAmounts']=='Yes'){ $DisplayPrice = number_format($POLine['unitprice'],2); } else { - $DisplayPrice = "----"; + $DisplayPrice = '----'; } $DisplayDelDate = ConvertSQLDate($POLine['deliverydate'],2); if ($_POST['ShowAmounts']=='Yes'){ $DisplayLineTotal = number_format($POLine['unitprice']*$POLine['quantityord'],2); } else { - $DisplayLineTotal = "----"; + $DisplayLineTotal = '----'; } /* Dont search for supplier data if it is a preview */ if ($OrderNo !='Preview') { //check the supplier code from code item $sqlsupp = "SELECT supplierdescription - FROM purchdata - WHERE stockid='" . $POLine['itemcode'] . "' - AND supplierno ='" . $POHeader['supplierno'] . "' - AND price='".$POLine['unitprice']."'"; + FROM purchdata + WHERE stockid='" . $POLine['itemcode'] . "' + AND supplierno ='" . $POHeader['supplierno'] . "' + AND price='".$POLine['unitprice']."'"; $SuppResult = DB_query($sqlsupp,$db); $SuppDescRow = DB_fetch_row($SuppResult); } else { @@ -237,7 +256,7 @@ if($SuppDescRow[0]==""){ $Desc=$POLine['itemdescription']; }else{ - $Desc="".$SuppDescRow['0']." - ".$POLine['itemdescription'].""; + $Desc= $SuppDescRow['0'].' - '.$POLine['itemdescription'].""; } $OrderTotal += ($POLine['unitprice']*$POLine['quantityord']); $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column1->x,$YPos,$FormDesign->Data->Column1->Length,$FormDesign->Data->Column1->FontSize,$POLine['itemcode'], 'left'); @@ -273,66 +292,46 @@ if ($_POST['ShowAmounts']=='Yes'){ $DisplayOrderTotal = number_format($OrderTotal,2); } else { - $DisplayOrderTotal = "----"; + $DisplayOrderTotal = '----'; } $pdf->addText($FormDesign->OrderTotalCaption->x,$Page_Height - $FormDesign->OrderTotalCaption->y, $FormDesign->OrderTotalCaption->FontSize, _('Order Total - excl tax'). ' ' . $POHeader['currcode']); $LeftOvers = $pdf->addTextWrap($FormDesign->OrderTotal->x,$Page_Height - $FormDesign->OrderTotal->y,$FormDesign->OrderTotal->Length,$FormDesign->OrderTotal->FontSize,$DisplayOrderTotal, 'right'); } /*end if there are order details to show on the order*/ //} /* end of check to see that there was an order selected to print */ - //failed var to allow us to print if the email fails. - $failed = false; + + $Success = 1; //assume the best and email goes - has to be set to 1 to allow update status if ($MakePDFThenDisplayIt){ - $pdf->OutputD($_SESSION['DatabaseName'] . '_PurchaseOrder_' . date('Y-m-d') . '.pdf');//UldisN + $pdf->OutputD($_SESSION['DatabaseName'] . '_PurchaseOrder_' . $OrderNo . '_' . date('Y-m-d') . '.pdf');//UldisN $pdf->__destruct(); //UldisN } else { /* must be MakingPDF to email it */ - /* UldisN - $pdfcode = $pdf->output(); - $fp = fopen( $_SESSION['reports_dir'] . '/PurchOrder.pdf','wb'); - fwrite ($fp, $pdfcode); - fclose ($fp); - */ - $PdfFileName = $_SESSION['DatabaseName'] . '_PurchaseOrder_' . date('Y-m-d') . '.pdf'; - $ReportsDirName = $_SESSION['reports_dir']; - $pdf->Output($ReportsDirName . '/' . $PdfFileName,'F');//UldisN - $pdf->__destruct(); //UldisN + + $PdfFileName = $_SESSION['DatabaseName'] . '_PurchaseOrder_' . $OrderNo . '_' .date('Y-m-d') . '.pdf'; + $pdf->Output($_SESSION['reports_dir'] . '/' . $PdfFileName,'F'); + $pdf->__destruct(); include('includes/htmlMimeMail.php'); $mail = new htmlMimeMail(); - $attachment = $mail->getFile($ReportsDirName . '/' . $PdfFileName); + $attachment = $mail->getFile($_SESSION['reports_dir'] . '/' . $PdfFileName); $mail->setText( _('Please find herewith our purchase order number').' ' . $OrderNo); $mail->setSubject( _('Purchase Order Number').' ' . $OrderNo); $mail->addAttachment($attachment, $PdfFileName, 'application/pdf'); $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . "<" . $_SESSION['CompanyRecord']['email'] .">"); - $result = $mail->send(array($_POST['EmailTo'])); - if ($result==1){ - $failed = false; - echo '<p>'; + $Success = $mail->send(array($_POST['EmailTo'])); + if ($Success==1){ + echo '<p />'; prnMsg( _('Purchase Order'). ' ' . $OrderNo.' ' . _('has been emailed to') .' ' . $_POST['EmailTo'] . ' ' . _('as directed'), 'success'); - } else { - $failed = true; - echo '<p>'; + } else { //email failed + echo '<p />'; prnMsg( _('Emailing Purchase order'). ' ' . $OrderNo.' ' . _('to') .' ' . $_POST['EmailTo'] . ' ' . _('failed'), 'error'); } } - if ($ViewingOnly==0 && !$failed) { - $commentsql="SELECT initiator,stat_comment FROM purchorders WHERE orderno='".$OrderNo."'"; - $commentresult=DB_query($commentsql,$db); - $commentrow=DB_fetch_array($commentresult); - $comment=$commentrow['stat_comment']; - $emailsql="SELECT email FROM www_users WHERE userid='".$commentrow['initiator']."'"; - $emailresult=DB_query($emailsql, $db); - $emailrow=DB_fetch_array($emailresult); - $date = date($_SESSION['DefaultDateFormat']); - $StatusComment=$date.' - Printed by <a href="mailto:'.$emailrow['email'].'">'.$_SESSION['UserID']. - '</a><br>'.$comment; - $sql = " - UPDATE purchorders - SET - allowprint = 0, - dateprinted = '" . Date('Y-m-d') . "', - status = '" . PurchOrder::STATUS_PRINTED . "', - stat_comment = '" . $StatusComment . "' - WHERE - purchorders.orderno = '" . $OrderNo."'"; + if ($ViewingOnly==0 AND $Success==1) { + $StatusComment = date($_SESSION['DefaultDateFormat']) .' - ' . _('Printed by') . '<a href="mailto:'.$_SESSION['UserEmail'] .'">'.$_SESSION['UsersRealName']. '</a><br />' . $POHeader['stat_comment']; + + $sql = "UPDATE purchorders SET allowprint = 0, + dateprinted = '" . Date('Y-m-d') . "', + status = 'Printed', + stat_comment = '" . $StatusComment . "' + WHERE purchorders.orderno = '" . $OrderNo."'"; $result = DB_query($sql,$db); } } /* There was enough info to either print or email the purchase order */ @@ -374,19 +373,19 @@ if ($_POST['PrintOrEmail']=='Email'){ $ErrMsg = _('There was a problem retrieving the contact details for the supplier'); $SQL = "SELECT suppliercontacts.contact, - suppliercontacts.email - FROM suppliercontacts INNER JOIN purchorders - ON suppliercontacts.supplierid=purchorders.supplierno - WHERE purchorders.orderno='".$OrderNo."'"; + suppliercontacts.email + FROM suppliercontacts INNER JOIN purchorders + ON suppliercontacts.supplierid=purchorders.supplierno + WHERE purchorders.orde... [truncated message content] |