3 /* $Revision: 1.14 $ */
5 /*The supplier transaction uses the SuppTrans class to hold the information about the invoice
6 the SuppTrans class contains an array of GRNs objects - containing details of GRNs for invoicing and also
7 an array of GLCodes objects - only used if the AP - GL link is effective */
12 include('includes/DefineSuppTransClass.php');
13 /* Session started in header.inc for password checking and authorisation level check */
14 include('includes/session.inc');
15 $title = _('Enter Supplier Invoice Against Goods Received');
16 include('includes/header.inc');
18 if (!isset($_SESSION['SuppTrans'])){
19 prnMsg(_('To enter a supplier transactions the supplier must first be selected from the supplier selection screen') . ', ' . _('then the link to enter a supplier invoice must be clicked on'),'info');
20 echo "<BR><A HREF='$rootpath/SelectSupplier.php?" . SID
."'>" . _('Select A Supplier to Enter a Transaction For') . '</A>';
21 include('includes/footer.inc');
23 /*It all stops here if there aint no supplier selected and invoice initiated ie $_SESSION['SuppTrans'] started off*/
26 /*If the user hit the Add to Invoice button then process this first before showing all GRNs on the invoice
27 otherwise it wouldnt show the latest additions*/
28 if (isset($_POST['AddPOToTrans']) AND $_POST['AddPOToTrans']!=''){
29 foreach($_SESSION['SuppTransTmp']->GRNs
as $GRNTmp) {
30 if ($_POST['AddPOToTrans']==$GRNTmp->PONo
) {
31 $_SESSION['SuppTrans']->Copy_GRN_To_Trans($GRNTmp);
32 $_SESSION['SuppTransTmp']->Remove_GRN_From_Trans($GRNTmp->GRNNo
);
37 if (isset($_POST['AddGRNToTrans'])){ /*adding a GRN to the invoice */
38 foreach($_SESSION['SuppTransTmp']->GRNs
as $GRNTmp) {
39 $Selected = $_POST['GRNNo_' . $GRNTmp->GRNNo
];
40 if ($Selected==True) {
41 $_SESSION['SuppTrans']->Copy_GRN_To_Trans($GRNTmp);
42 $_SESSION['SuppTransTmp']->Remove_GRN_From_Trans($GRNTmp->GRNNo
);
47 if (isset($_POST['ModifyGRN'])){
51 if ($_POST['This_QuantityInv'] >= ($_POST['QtyRecd'] - $_POST['Prev_QuantityInv'])){
56 if ($_SESSION['Check_Qty_Charged_vs_Del_Qty']==True) {
57 if (($_POST['This_QuantityInv']+
$_POST['Prev_QuantityInv'])/($_POST['QtyRecd'] ) > (1+
($_SESSION['OverChargeProportion'] / 100))){
58 prnMsg(_('The quantity being invoiced is more than the outstanding quantity by more than') . ' ' . $_SESSION['OverChargeProportion'] . ' ' . _('percent. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary'),'error');
62 if (!is_numeric($_POST['ChgPrice']) AND $_POST['ChgPrice']<0){
64 prnMsg(_('The price charged in the suppliers currency is either not numeric or negative') . '. ' . _('The goods received cannot be invoiced at this price'),'error');
65 } elseif ($_SESSION['Check_Price_Charged_vs_Order_Price'] == True) {
66 if ($_POST['ChgPrice']/$_POST['OrderPrice'] > (1+
($_SESSION['OverChargeProportion'] / 100))){
67 prnMsg(_('The price being invoiced is more than the purchase order price by more than') . ' ' . $_SESSION['OverChargeProportion'] . '%. ' . _('The system is set up to prohibit this') . '. ' . _('See the system administrator to modify the set up parameters if necessary'),'error');
72 if ($InputError==False){
73 // $_SESSION['SuppTrans']->Remove_GRN_From_Trans($_POST['GRNNumber']);
74 $_SESSION['SuppTrans']->Modify_GRN_To_Trans($_POST['GRNNumber'],
75 $_POST['PODetailItem'],
77 $_POST['ItemDescription'],
79 $_POST['Prev_QuantityInv'],
80 $_POST['This_QuantityInv'],
84 $_POST['StdCostUnit'],
91 if (isset($_GET['Delete'])){
92 $_SESSION['SuppTransTmp']->Copy_GRN_To_Trans($_SESSION['SuppTrans']->GRNs
[$_GET['Delete']]);
93 $_SESSION['SuppTrans']->Remove_GRN_From_Trans($_GET['Delete']);
97 /*Show all the selected GRNs so far from the SESSION['SuppTrans']->GRNs array */
99 echo '<CENTER><FONT SIZE=4 COLOR=BLUE>' . _('Invoiced Goods Received Selected');
100 echo '<TABLE CELLPADDING=1>';
102 $tableheader = "<TR BGCOLOR=#800000>
103 <TD class='tableheader'>" . _('Sequence') . " #</TD>
104 <TD class='tableheader'>" . _('Item Code') . "</TD>
105 <TD class='tableheader'>" . _('Description') . "</TD>
106 <TD class='tableheader'>" . _('Quantity Charged') . "</TD>
107 <TD class='tableheader'>" . _('Price Charge in') . ' ' . $_SESSION['SuppTrans']->CurrCode
. "</TD>
108 <TD class='tableheader'>" . _('Line Value in') . ' ' . $_SESSION['SuppTrans']->CurrCode
. '</TD></TR>';
112 $TotalValueCharged=0;
114 foreach ($_SESSION['SuppTrans']->GRNs
as $EnteredGRN){
116 echo '<TR><TD>' . $EnteredGRN->GRNNo
. '</TD>
117 <TD>' . $EnteredGRN->ItemCode
. '</TD>
118 <TD>' . $EnteredGRN->ItemDescription
. '</TD>
119 <TD ALIGN=RIGHT>' . number_format($EnteredGRN->This_QuantityInv
,2) . '</TD>
120 <TD ALIGN=RIGHT>' . number_format($EnteredGRN->ChgPrice
,2) . '</TD>
121 <TD ALIGN=RIGHT>' . number_format($EnteredGRN->ChgPrice
* $EnteredGRN->This_QuantityInv
,2) . "</TD>
122 <TD><A HREF='" . $_SERVER['PHP_SELF'] . '?' . SID
. '&Modify=' . $EnteredGRN->GRNNo
. "'>". _('Modify') . "</A></TD>
123 <TD><A HREF='" . $_SERVER['PHP_SELF'] . '?' . SID
. '&Delete=' . $EnteredGRN->GRNNo
. "'>" . _('Delete') . "</A></TD>
126 $TotalValueCharged = $TotalValueCharged +
($EnteredGRN->ChgPrice
* $EnteredGRN->This_QuantityInv
);
136 <TD COLSPAN=5 ALIGN=RIGHT><FONT SIZE=4 COLOR=BLUE>' . _('Total Value of Goods Charged') . ':</FONT></TD>
137 <TD ALIGN=RIGHT><FONT SIZE=4 COLOR=BLUE><U>' . number_format($TotalValueCharged,2) . '</U></FONT></TD>
139 echo "</TABLE><BR><A HREF='$rootpath/SupplierInvoice.php?" . SID
."'>" . _('Back to Invoice Entry') . '</A><HR>';
142 /* Now get all the outstanding GRNs for this supplier from the database*/
144 $SQL = "SELECT grnbatch,
146 purchorderdetails.orderno,
147 purchorderdetails.unitprice,
150 grns.itemdescription,
154 purchorderdetails.glcode,
155 purchorderdetails.shiptref,
156 purchorderdetails.jobref,
157 purchorderdetails.podetailitem
158 FROM grns INNER JOIN purchorderdetails
159 ON grns.podetailitem=purchorderdetails.podetailitem
160 WHERE grns.supplierid ='" . $_SESSION['SuppTrans']->SupplierID
. "'
161 AND grns.qtyrecd - grns.quantityinv > 0
162 ORDER BY grns.grnno";
163 $GRNResults = DB_query($SQL,$db);
165 if (DB_num_rows($GRNResults)==0){
166 prnMsg(_('There are no outstanding goods received from') . ' ' . $_SESSION['SuppTrans']->SupplierName
. ' ' . _('that have not been invoiced by them') . '<BR>' . _('The goods must first be received using the link below to select purchase orders to receive'),'error');
167 echo "<P><A HREF='$rootpath/PO_SelectOSPurchOrder.php?" . SID
. 'SupplierID=' . $_SESSION['SuppTrans']->SupplierID
."'>" . _('Select Purchase Orders to receive') .'</A>';
168 include('includes/footer.inc');
172 /*Set up a table to show the GRNs outstanding for selection */
173 echo "<FORM ACTION='" . $_SERVER['PHP_SELF'] . "?" . SID
. "' METHOD=POST>";
175 if (!isset( $_SESSION['SuppTransTmp'])){
176 $_SESSION['SuppTransTmp'] = new SuppTrans
;
177 while ($myrow=DB_fetch_array($GRNResults)){
179 $GRNAlreadyOnInvoice = False;
181 foreach ($_SESSION['SuppTrans']->GRNs
as $EnteredGRN){
182 if ($EnteredGRN->GRNNo
== $myrow['grnno']) {
183 $GRNAlreadyOnInvoice = True;
186 if ($GRNAlreadyOnInvoice == False){
187 $_SESSION['SuppTransTmp']->Add_GRN_To_Trans($myrow['grnno'],
188 $myrow['podetailitem'],
190 $myrow['itemdescription'],
192 $myrow['quantityinv'],
193 $myrow['qtyrecd'] - $myrow['quantityinv'],
197 $myrow['stdcostunit'],
207 //if (isset($_POST['GRNNo']) AND $_POST['GRNNo']!=''){
208 if (isset($_GET['Modify'])){
209 $GRNNo = $_GET['Modify'];
210 $GRNTmp = $_SESSION['SuppTrans']->GRNs
[$GRNNo];
212 echo '<P><FONT SIZE=4 COLOR=BLUE><B>' . _('GRN Selected For Adding To A Purchase Invoice') . '</FONT></B>';
215 <TD class='tableheader'>" . _('Sequence') . " #</TD>
216 <TD class='tableheader'>" . _('Item') . "</TD>
217 <TD class='tableheader'>" . _('Qty Outstanding') . "</TD>
218 <TD class='tableheader'>" . _('Qty Invoiced') . "</TD>
219 <TD class='tableheader'>" . _('Order Price in') . ' ' . $_SESSION['SuppTrans']->CurrCode
. "</TD>
220 <TD class='tableheader'>" . _('Actual Price in') . ' ' . $_SESSION['SuppTrans']->CurrCode
. "</TD>
224 <TD>' . $GRNTmp->GRNNo
. '</TD>
225 <TD>' . $GRNTmp->ItemCode
. ' ' . $GRNTmp->ItemDescription
. '</TD>
226 <TD ALIGN=RIGHT>' . number_format($GRNTmp->QtyRecd
- $GRNTmp->Prev_QuantityInv
,2) . "</TD>
227 <TD><INPUT TYPE=Text Name='This_QuantityInv' Value=" . $GRNTmp->This_QuantityInv
. ' SIZE=11 MAXLENGTH=10></TD>
228 <TD ALIGN=RIGHT>' . $GRNTmp->OrderPrice
. '</TD>
229 <TD><INPUT TYPE=Text Name="ChgPrice" Value=' . $GRNTmp->ChgPrice
. ' SIZE=11 MAXLENGTH=10></TD>
233 /* if ($myrow['closed']==1){ //Shipment is closed so pre-empt problems later by warning the user - need to modify the order first
234 echo "<INPUT TYPE=HIDDEN NAME='ShiptRef' Value=''>";
235 echo "<P>Unfortunately, the shipment that this purchase order line item was allocated to has been closed - if you add this item to the transaction then no shipments will not be updated. If you wish to allocate the order line item to a different shipment the order must be modified first.";
237 echo "<INPUT TYPE=HIDDEN NAME='ShiptRef' Value='" . $GRNTmp->ShiptRef
. "'>";
240 echo "<P><INPUT TYPE=Submit Name='ModifyGRN' Value='" . _('Modify Line') . "'>";
243 echo "<INPUT TYPE=HIDDEN NAME='GRNNumber' VALUE=" . $GRNTmp->GRNNo
. '>';
244 echo "<INPUT TYPE=HIDDEN NAME='ItemCode' VALUE='" . $GRNTmp->ItemCode
. "'>";
245 echo "<INPUT TYPE=HIDDEN NAME='ItemDescription' VALUE='" . $GRNTmp->ItemDescription
. "'>";
246 echo "<INPUT TYPE=HIDDEN NAME='QtyRecd' VALUE=" . $GRNTmp->QtyRecd
. ">";
247 echo "<INPUT TYPE=HIDDEN NAME='Prev_QuantityInv' VALUE=" . $GRNTmp->Prev_QuantityInv
. '>';
248 echo "<INPUT TYPE=HIDDEN NAME='OrderPrice' VALUE=" . $GRNTmp->OrderPrice
. '>';
249 echo "<INPUT TYPE=HIDDEN NAME='StdCostUnit' VALUE=" . $GRNTmp->StdCostUnit
. '>';
250 echo "<INPUT TYPE=HIDDEN NAME='JobRef' Value='" . $GRNTmp->JobRef
. "'>";
251 echo "<INPUT TYPE=HIDDEN NAME='GLCode' Value='" . $GRNTmp->GLCode
. "'>";
252 echo "<INPUT TYPE=HIDDEN NAME='PODetailItem' Value='" . $GRNTmp->PODetailItem
. "'>";
255 if (count( $_SESSION['SuppTransTmp']->GRNs
)>0){ /*if there are any outstanding GRNs then */
256 echo '<CENTER><FONT SIZE=4 COLOR=BLUE>' . _('Goods Received Yet to be Invoiced From') . ' ' . $_SESSION['SuppTrans']->SupplierName
;
257 echo "<TABLE CELLPADDING=1 COLSPAN=7>";
259 $tableheader = "<TR BGCOLOR=#800000><TD class='tableheader'>" . _('Select') . "</TD>
260 <TD class='tableheader'>" . _('Sequence') . " #</TD>
261 <TD class='tableheader'>" . _('Order') . "</TD>
262 <TD class='tableheader'>" . _('Item Code') . "</TD>
263 <TD class='tableheader'>" . _('Description') . "</TD>
264 <TD class='tableheader'>" . _('Total Qty Received') . "</TD>
265 <TD class='tableheader'>" . _('Qty Already Invoiced') . "</TD>
266 <TD class='tableheader'>" . _('Qty Yet To Invoice') . "</TD>
267 <TD class='tableheader'>" . _('Order Price in') . ' ' . $_SESSION['SuppTrans']->CurrCode
. "</TD>
268 <TD class='tableheader'>" . _('Line Value in') . ' ' . $_SESSION['SuppTrans']->CurrCode
. '</TD></TR>';
272 foreach ($_SESSION['SuppTransTmp']->GRNs
as $GRNTmp){
274 $_SESSION['SuppTransTmp']->GRNs
[$GRNTmp->GRNNo
]->This_QuantityInv
= $GRNTmp->QtyRecd
- $GRNTmp->Prev_QuantityInv
;
276 if ($POs[$GRNTmp->PONo
] != $GRNTmp->PONo
) {
277 $POs[$GRNTmp->PONo
] = $GRNTmp->PONo
;
278 echo "<TR><TD><INPUT TYPE=Submit Name='AddPOToTrans' Value='" . $GRNTmp->PONo
. "'></TD><TD COLSPAN=3>" . _('Add Whole PO to Invoice') . '</TD></TR>';
285 <TD><INPUT TYPE=checkbox NAME='GRNNo_" . $GRNTmp->GRNNo
. "'></TD>
286 <TD>" . $GRNTmp->GRNNo
. '</TD>
287 <TD>' . $GRNTmp->PODetailItem
. '</TD>
288 <TD>' . $GRNTmp->ItemCode
. '</TD>
289 <TD>' . $GRNTmp->ItemDescription
. '</TD>
290 <TD ALIGN=RIGHT>' . $GRNTmp->QtyRecd
. '</TD>
291 <TD ALIGN=RIGHT>' . $GRNTmp->Prev_QuantityInv
. '</TD>
292 <TD ALIGN=RIGHT>' . ($GRNTmp->QtyRecd
- $GRNTmp->Prev_QuantityInv
) . '</TD>
293 <TD ALIGN=RIGHT>' . $GRNTmp->OrderPrice
. '</TD>
294 <TD ALIGN=RIGHT>' . number_format($GRNTmp->OrderPrice
* ($GRNTmp->QtyRecd
- $GRNTmp->Prev_QuantityInv
),2) . '</TD>
302 echo "<P><INPUT TYPE=Submit Name='AddGRNToTrans' Value='" . _('Add to Invoice') . "'>";
307 include('includes/footer.inc');