PageRenderTime 101ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/chronique/ShipmentCosting.php

http://chronique.googlecode.com/
PHP | 716 lines | 519 code | 144 blank | 53 comment | 48 complexity | 40aafe5318462dc5c36731009fff0e2b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* $Id: ShipmentCosting.php 4786 2011-12-22 09:44:35Z daintree $*/
  3. include('includes/session.inc');
  4. $title = _('Shipment Costing');
  5. /* Session started in header.inc for password checking and authorisation level check */
  6. include('includes/header.inc');
  7. include('includes/SQL_CommonFunctions.inc');
  8. echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" title="' . _('Search') .
  9. '" alt="" />' . ' ' . $title . '</p>';
  10. if (isset($_GET['NewShipment']) AND $_GET['NewShipment']=='Yes'){
  11. unset($_SESSION['Shipment']->LineItems);
  12. unset($_SESSION['Shipment']);
  13. }
  14. if (!isset($_GET['SelectedShipment'])){
  15. echo '<br />';
  16. prnMsg( _('This page is expected to be called with the shipment number to show the costing for'), 'error');
  17. include ('includes/footer.inc');
  18. exit;
  19. }
  20. $ShipmentHeaderSQL = "SELECT shipments.supplierid,
  21. suppliers.suppname,
  22. shipments.eta,
  23. suppliers.currcode,
  24. shipments.vessel,
  25. shipments.voyageref,
  26. shipments.closed
  27. FROM shipments INNER JOIN suppliers
  28. ON shipments.supplierid = suppliers.supplierid
  29. WHERE shipments.shiptref = '" . $_GET['SelectedShipment'] . "'";
  30. $ErrMsg = _('Shipment').' '. $_GET['SelectedShipment'] . ' ' . _('cannot be retrieved because a database error occurred');
  31. $GetShiptHdrResult = DB_query($ShipmentHeaderSQL,$db, $ErrMsg);
  32. if (DB_num_rows($GetShiptHdrResult)==0) {
  33. echo '<br />';
  34. prnMsg( _('Shipment') . ' ' . $_GET['SelectedShipment'] . ' ' . _('could not be located in the database') , 'error');
  35. include ('includes/footer.inc');
  36. exit;
  37. }
  38. $HeaderData = DB_fetch_array($GetShiptHdrResult);
  39. echo '<br />
  40. <table class="selection">
  41. <tr>
  42. <th colspan="4"><font size="3" color="navy">'._('Shipment Details').'</font></th>
  43. </tr>
  44. <tr>
  45. <td><b>'. _('Shipment') .': </td>
  46. <td><b>' . $_GET['SelectedShipment'] . '</b></td>
  47. <td><b>'. _('From').' ' . $HeaderData['suppname'] . '</b></td>
  48. </tr>
  49. <tr>
  50. <td>' . _('Vessel'). ': </td>
  51. <td>' . $HeaderData['vessel'] . '</td>
  52. <td>'. _('Voyage Ref'). ': </td>
  53. <td>' . $HeaderData['voyageref'] . '</td>
  54. </tr>
  55. <tr>
  56. <td>' . _('Expected Arrival Date (ETA)') . ': </td>
  57. <td>' . ConvertSQLDate($HeaderData['eta']) . '</td>
  58. </tr>
  59. </table>';
  60. /*Get the total non-stock item shipment charges */
  61. $sql = "SELECT SUM(value)
  62. FROM shipmentcharges
  63. WHERE stockid=''
  64. AND shiptref ='" . $_GET['SelectedShipment']. "'";
  65. $ErrMsg = _('Shipment') . ' ' . $_GET['SelectedShipment'] . ' ' . _('general costs cannot be retrieved from the database');
  66. $GetShiptCostsResult = DB_query($sql,$db, $ErrMsg);
  67. if (DB_num_rows($GetShiptCostsResult)==0) {
  68. echo '<br />';
  69. prnMsg (_('No General Cost Records exist for Shipment') . ' ' . $_GET['SelectedShipment'] . ' ' . _('in the database'), 'error');
  70. include ('includes/footer.inc');
  71. exit;
  72. }
  73. $myrow = DB_fetch_row($GetShiptCostsResult);
  74. $TotalCostsToApportion = $myrow[0];
  75. /*Now Get the total of stock items invoiced against the shipment */
  76. $sql = "SELECT SUM(value)
  77. FROM shipmentcharges
  78. WHERE stockid<>''
  79. AND shiptref ='" . $_GET['SelectedShipment'] . "'";
  80. $ErrMsg = _('Shipment') . ' ' . $_GET['SelectedShipment'] . ' ' . _('Item costs cannot be retrieved from the database');
  81. $GetShiptCostsResult = DB_query($sql,$db);
  82. if (DB_error_no($db) !=0 OR DB_num_rows($GetShiptCostsResult)==0) {
  83. echo '<br />';
  84. prnMsg ( _('No Item Cost Records exist for Shipment') . ' ' . $_GET['SelectedShipment'] . ' ' . _('in the database'), 'error');
  85. include ('includes/footer.inc');
  86. exit;
  87. }
  88. $myrow = DB_fetch_row($GetShiptCostsResult);
  89. $TotalInvoiceValueOfShipment = $myrow[0];
  90. /*Now get the lines on the shipment */
  91. $LineItemsSQL = "SELECT purchorderdetails.itemcode,
  92. purchorderdetails.itemdescription,
  93. SUM(purchorderdetails.qtyinvoiced) as totqtyinvoiced,
  94. SUM(purchorderdetails.quantityrecd) as totqtyrecd
  95. FROM purchorderdetails
  96. WHERE purchorderdetails.shiptref='" . $_GET['SelectedShipment'] . "'
  97. GROUP BY purchorderdetails.itemcode,
  98. purchorderdetails.itemdescription";
  99. $ErrMsg = _('The lines on the shipment could not be retrieved from the database');
  100. $LineItemsResult = db_query($LineItemsSQL,$db, $ErrMsg);
  101. if (db_num_rows($LineItemsResult) > 0) {
  102. if (isset($_POST['Close'])){
  103. while ($myrow=DB_fetch_array($LineItemsResult)){
  104. if ($myrow['totqtyinvoiced'] < $myrow['totqtyrecd']){
  105. prnMsg(_('Cannot close a shipment where the quantity received is more than the quantity invoiced. Check the item') . ' ' . $myrow['itemcode'] . ' - ' . $myrow['itemdescription'],'warn');
  106. unset($_POST['Close']);
  107. }
  108. }
  109. DB_data_seek($LineItemsResult,0);
  110. }
  111. if (isset($_POST['Close'])){
  112. /*Set up a transaction to buffer all updates or none */
  113. $result = DB_Txn_Begin($db);
  114. $PeriodNo = GetPeriod(Date($_SESSION['DefaultDateFormat']), $db);
  115. }
  116. echo '<br /><table cellpadding="2" colspan="7" class="selection">';
  117. echo '<tr>
  118. <th colspan="9"><font color="navy" size="3">' . _('Items on shipment'). '</font></th></tr>';
  119. $TableHeader = '<tr>
  120. <th>'. _('Item'). '</th>
  121. <th>'. _('Quantity'). '<br />'. _('Invoiced'). '</th>
  122. <th>'. _('Quantity'). '<br />'. _('Received'). '</th>
  123. <th>'. _('Invoiced'). '<br />'. _('Charges'). '</th>
  124. <th>'. _('Shipment'). '<br />'. _('Charges'). '</th>
  125. <th>'. _('Shipment'). '<br />'. _('Cost'). '</th>
  126. <th>'. _('Standard'). '<br />'. _('Cost'). '</th>
  127. <th>'. _('Variance'). '</th>
  128. <th>%</th>
  129. </tr>';
  130. echo $TableHeader;
  131. /*show the line items on the shipment with the value invoiced and shipt cost */
  132. $k=0; //row colour counter
  133. $TotalShiptVariance = 0;
  134. $RowCounter =0;
  135. while ($myrow=DB_fetch_array($LineItemsResult)) {
  136. if ($k==1){
  137. echo '<tr class="EvenTableRows">';
  138. $k=0;
  139. } else {
  140. echo '<tr class="OddTableRows">';
  141. $k=1;
  142. }
  143. $sql = "SELECT SUM(shipmentcharges.value) AS invoicedcharges
  144. FROM shipmentcharges
  145. WHERE shipmentcharges.stockid ='" . $myrow['itemcode'] . "'
  146. AND shipmentcharges.shiptref='" . $_GET['SelectedShipment'] . "'";
  147. $ItemChargesResult = DB_query($sql,$db);
  148. $ItemChargesRow = DB_fetch_row($ItemChargesResult);
  149. $ItemCharges = $ItemChargesRow[0];
  150. if ($TotalInvoiceValueOfShipment>0){
  151. $PortionOfCharges = $TotalCostsToApportion *($ItemCharges/$TotalInvoiceValueOfShipment);
  152. } else {
  153. $PortionOfCharges = 0;
  154. }
  155. if ($myrow['totqtyinvoiced']>0){
  156. $ItemShipmentCost = ($ItemCharges+$PortionOfCharges)/$myrow['totqtyrecd'];
  157. } else {
  158. $ItemShipmentCost =0;
  159. }
  160. $sql = "SELECT SUM(grns.stdcostunit*grns.qtyrecd) AS costrecd
  161. FROM grns INNER JOIN purchorderdetails
  162. ON grns.podetailitem=purchorderdetails.podetailitem
  163. WHERE purchorderdetails.shiptref='" . $_GET['SelectedShipment'] . "'
  164. AND purchorderdetails.itemcode = '" . $myrow['itemcode'] . "'";
  165. $StdCostResult = DB_query($sql,$db);
  166. $StdCostRow = DB_fetch_row($StdCostResult);
  167. $CostRecd = $StdCostRow[0];
  168. if ($myrow['totqtyrecd']==0) {
  169. $StdCostUnit = 0;
  170. } else {
  171. $StdCostUnit = $StdCostRow[0]/$myrow['totqtyrecd'];
  172. }
  173. if ($ItemShipmentCost !=0){
  174. $Variance = $StdCostUnit - $ItemShipmentCost;
  175. } else {
  176. $Variance =0;
  177. }
  178. $TotalShiptVariance += ($Variance *$myrow['totqtyinvoiced']);
  179. if ($StdCostUnit>0 ){
  180. $VariancePercentage = locale_number_format(($Variance*100)/$StdCostUnit,1);
  181. } else {
  182. $VariancePercentage =100;
  183. }
  184. if ( isset($_POST['Close']) AND $Variance !=0){
  185. if ($_SESSION['CompanyRecord']['gllink_stock']==1){
  186. $StockGLCodes = GetStockGLCode($myrow['itemcode'],$db);
  187. }
  188. /*GL journals depend on the costing method used currently:
  189. Standard cost - the price variance between the exisitng system cost and the shipment cost is taken as a variance
  190. to the price varaince account
  191. Weighted Average Cost - the price variance is taken to the stock account and the cost updated to ensure the GL
  192. stock account ties up to the stock valuation
  193. */
  194. if ($_SESSION['WeightedAverageCosting'] == 1){ /* Do the WAvg journal and cost update */
  195. /*
  196. First off figure out the new weighted average cost Need the following data:
  197. How many in stock now
  198. The quantity being costed here - $myrow['qtyinvoiced']
  199. The cost of these items - $ItemShipmentCost
  200. */
  201. $sql ="SELECT SUM(quantity) FROM locstock WHERE stockid='" . $myrow['itemcode'] . "'";
  202. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The quantity on hand could not be retrieved from the database');
  203. $DbgMsg = _('The following SQL to retrieve the total stock quantity was used');
  204. $Result = DB_query($sql, $db, $ErrMsg, $DbgMsg);
  205. $QtyRow = DB_fetch_row($Result);
  206. $TotalQuantityOnHand = $QtyRow[0];
  207. /*The cost adjustment is the price variance / the total quantity in stock
  208. But that's only provided that the total quantity in stock is > the quantity charged on this invoice
  209. */
  210. $WriteOffToVariances =0;
  211. if ($myrow['totqtyinvoiced'] > $TotalQuantityOnHand){
  212. /*So we need to write off some of the variance to variances and
  213. only the balance of the quantity in stock to go to stock value */
  214. $WriteOffToVariances = ($myrow['totqtyinvoiced'] - $TotalQuantityOnHand) * ($ItemShipmentCost - $StdCostUnit);
  215. }
  216. if ($_SESSION['CompanyRecord']['gllink_stock']==1){
  217. /* If the quantity on hand is less the amount charged on this invoice then some must have been sold
  218. and the price variance on these must be written off to price variances*/
  219. if ($myrow['totqtyinvoiced'] > $TotalQuantityOnHand){
  220. $sql = "INSERT INTO gltrans (type,
  221. typeno,
  222. trandate,
  223. periodno,
  224. account,
  225. narrative,
  226. amount)
  227. VALUES (31,
  228. '" . $_GET['SelectedShipment'] . "',
  229. '" . Date('Y-m-d') . "',
  230. '" . $PeriodNo . "',
  231. '" . $StockGLCodes['purchpricevaract'] . "',
  232. '" . $myrow['itemcode'] . ' ' . _('shipment cost') . ' ' . locale_number_format($ItemShipmentCost,$_SESSION['CompanyRecord']['deicmalplaces']) . _('shipment quantity > stock held - variance write off') . "',
  233. " . $WriteOffToVariances . ")";
  234. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL entry for the shipment variance posting for'). ' ' . $myrow['itemcode'] . ' '. _('could not be inserted into the database because');
  235. $result = DB_query($sql,$db, $ErrMsg,'',TRUE);
  236. }
  237. /*Now post any remaining price variance to stock rather than price variances */
  238. $sql = "INSERT INTO gltrans (type,
  239. typeno,
  240. trandate,
  241. periodno,
  242. account,
  243. narrative,
  244. amount)
  245. VALUES (31,
  246. '" . $_GET['SelectedShipment'] . "',
  247. '" . Date('Y-m-d') . "',
  248. '" . $PeriodNo . "',
  249. '" . $StockGLCodes['stockact'] . "',
  250. '" . $myrow['itemcode'] . ' ' . _('shipment avg cost adjt') . "',
  251. '" . ($myrow['totqtyinvoiced'] *($ItemShipmentCost - $StdCostUnit)- $WriteOffToVariances) . "')";
  252. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL entry for the shipment average cost adjustment for'). ' ' . $myrow['itemcode'] . ' '. _('could not be inserted into the database because');
  253. $result = DB_query($sql,$db, $ErrMsg,'',TRUE);
  254. } /* end of average cost GL stuff */
  255. /*Now to update the stock cost with the new weighted average */
  256. /*Need to consider what to do if the cost has been changed manually between receiving
  257. the stock and entering the invoice - this code assumes there has been no cost updates
  258. made manually and all the price variance is posted to stock.
  259. A nicety or important?? */
  260. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The cost could not be updated because');
  261. $DbgMsg = _('The following SQL to update the cost was used');
  262. if ($TotalQuantityOnHand>0) {
  263. $CostIncrement = ($myrow['totqtyinvoiced'] *($ItemShipmentCost - $StdCostUnit) - $WriteOffToVariances) / $TotalQuantityOnHand;
  264. $sql = "UPDATE stockmaster
  265. SET lastcost=materialcost+overheadcost+labourcost,
  266. materialcost=materialcost+" . $CostIncrement . ",
  267. lastcostupdate='" . Date('Y-m-d') . "'
  268. WHERE stockid='" . $myrow['itemcode'] . "'";
  269. $Result = DB_query($sql, $db, $ErrMsg, $DbgMsg,'',TRUE);
  270. } else {
  271. $sql = "UPDATE stockmaster
  272. SET lastcost=materialcost+overheadcost+labourcost,
  273. materialcost='" . $ItemShipmentCost . "',
  274. lastcostupdate='" . Date('Y-m-d') . "'
  275. WHERE stockid='" . $myrow['itemcode'] . "'";
  276. $Result = DB_query($sql, $db, $ErrMsg, $DbgMsg,'',TRUE);
  277. }
  278. /* End of Weighted Average Costing Code */
  279. } else { /*We must be using standard costing do the journals for standard costing then */
  280. if ($_SESSION['CompanyRecord']['gllink_stock']==1){
  281. $sql = "INSERT INTO gltrans (type,
  282. typeno,
  283. trandate,
  284. periodno,
  285. account,
  286. narrative,
  287. amount)
  288. VALUES (31,
  289. '" . $_GET['SelectedShipment'] . "',
  290. '" . Date('Y-m-d') . "',
  291. '" . $PeriodNo . "',
  292. '" . $StockGLCodes['purchpricevaract'] . "',
  293. '" . $myrow['itemcode'] . ' ' . _('shipment cost') . ' ' . locale_number_format($ItemShipmentCost,$_SESSION['CompanyRecord']['decimalplaces']) . ' x ' . _('Qty recd') .' ' . $myrow['totqtyrecd'] . "',
  294. " . -$Variance * $myrow['totqtyrecd'] . ")";
  295. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The Positive GL entry for the shipment variance posting for'). ' ' . $myrow['itemcode'] . ' '. _('could not be inserted into the database because');
  296. $result = DB_query($sql,$db, $ErrMsg,'',TRUE);
  297. }
  298. } /* end of the costing specific updates */
  299. if ($_SESSION['CompanyRecord']['gllink_stock']==1){
  300. /*we always need to reverse entries relating to the GRN suspense during delivery and entry of shipment charges */
  301. $sql = "INSERT INTO gltrans (type,
  302. typeno,
  303. trandate,
  304. periodno,
  305. account,
  306. narrative,
  307. amount)
  308. VALUES (31,
  309. '" . $_GET['SelectedShipment'] . "',
  310. '" . Date('Y-m-d') . "',
  311. '" . $PeriodNo . "',
  312. '" . $_SESSION['CompanyRecord']['grnact'] . "',
  313. '" . $myrow['itemcode'] . ' ' ._('shipment cost') . ' ' . locale_number_format($ItemShipmentCost,$_SESSION['CompanyRecord']['decimalplaces']) . ' x ' . _('Qty invoiced') . ' ' . $myrow['totqtyinvoiced'] . "',
  314. " . ($Variance * $myrow['totqtyinvoiced']) . ")";
  315. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The credit GL entry for the shipment variance posting for') . ' ' . $myrow['itemcode'] . ' ' . _('could not be inserted because');
  316. $result = DB_query($sql,$db, $ErrMsg,'',TRUE);
  317. }
  318. if ( $_POST['UpdateCost'] == 'Yes' ){ /*Only ever a standard costing option
  319. Weighted average costing implies cost updates taking place automatically */
  320. $QOHResult = DB_query("SELECT SUM(quantity)
  321. FROM locstock
  322. WHERE stockid ='" . $myrow['itemcode'] . "'",$db);
  323. $QOHRow = DB_fetch_row($QOHResult);
  324. $QOH=$QOHRow[0];
  325. if ($_SESSION['CompanyRecord']['gllink_stock']==1){
  326. $CostUpdateNo = GetNextTransNo(35, $db);
  327. $PeriodNo = GetPeriod(Date('d/m/Y'), $db);
  328. $ValueOfChange = $QOH * ($ItemShipmentCost - $StdCostUnit);
  329. $SQL = "INSERT INTO gltrans (type,
  330. typeno,
  331. trandate,
  332. periodno,
  333. account,
  334. narrative,
  335. amount)
  336. VALUES (35,
  337. '" . $CostUpdateNo . "',
  338. '" . Date('Y-m-d') . "',
  339. '" . $PeriodNo . "',
  340. '" . $StockGLCodes['adjglact'] . "',
  341. '" . _('Shipment of') . ' ' . $myrow['itemcode'] . " " . _('cost was') . ' ' . $StdCostUnit . ' ' . _('changed to') . ' ' . locale_number_format($ItemShipmentCost,$_SESSION['CompanyRecord']['decimalplaces']) . ' x ' . _('QOH of') . ' ' . $QOH . "',
  342. " . -$ValueOfChange . ")";
  343. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL credit for the shipment stock cost adjustment posting could not be inserted because'). ' ' . DB_error_msg($db);
  344. $Result = DB_query($SQL,$db, $ErrMsg,'',TRUE);
  345. $SQL = "INSERT INTO gltrans (type,
  346. typeno,
  347. trandate,
  348. periodno,
  349. account,
  350. narrative,
  351. amount)
  352. VALUES (35,
  353. '" . $CostUpdateNo . "',
  354. '" . Date('Y-m-d') . "',
  355. '" . $PeriodNo . "',
  356. '" . $StockGLCodes['stockact'] . "',
  357. '" . _('Shipment of') . ' ' . $myrow['itemcode'] . ' ' . _('cost was') . ' ' . $StdCostUnit . ' ' . _('changed to') . ' ' . locale_number_format($ItemShipmentCost,$_SESSION['CompanyRecord']['decimalplaces']) . ' x ' . _('QOH of') . ' ' . $QOH . "',
  358. " . $ValueOfChange . ")";
  359. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL debit for stock cost adjustment posting could not be inserted because') .' '. DB_error_msg($db);
  360. $Result = DB_query($SQL,$db, $ErrMsg,'',TRUE);
  361. } /*end of GL entries for a standard cost update */
  362. /* Only the material cost is important for imported items */
  363. $sql = "UPDATE stockmaster SET materialcost=" . $ItemShipmentCost . ",
  364. labourcost=0,
  365. overheadcost=0,
  366. lastcost='" . $StdCostUnit . "',
  367. lastcostupdate='" . Date('Y-m-d') . "'
  368. WHERE stockid='" . $myrow['itemcode'] . "'";
  369. $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The shipment cost details for the stock item could not be updated because'). ': ' . DB_error_msg($db);
  370. $result = DB_query($sql,$db, $ErrMsg,'',TRUE);
  371. } // end of update cost code
  372. } // end of Close shipment item updates
  373. /* Item / Qty Inv/ FX price/ Local Val/ Portion of chgs/ Shipt Cost/ Std Cost/ Variance/ Var % */
  374. echo '<td>' . $myrow['itemcode'] . ' - ' . $myrow['itemdescription'] . '</td>
  375. <td class="number">' . locale_number_format($myrow['totqtyinvoiced'],'Variable') . '</td>
  376. <td class="number">' . locale_number_format($myrow['totqtyrecd'],'Variable') . '</td>
  377. <td class="number">' . locale_number_format($ItemCharges,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  378. <td class="number">' . locale_number_format($PortionOfCharges,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  379. <td class="number">' . locale_number_format($ItemShipmentCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  380. <td class="number">' . locale_number_format($StdCostUnit,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  381. <td class="number">' . locale_number_format($Variance,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  382. <td class="number">' . $VariancePercentage . '%</td></tr>';
  383. }
  384. }
  385. echo '<tr>
  386. <td colspan=3 class="number"><font color=BLUE><b>'. _('Total Shipment Charges'). '</b></font></td>
  387. <td class="number">' . locale_number_format($TotalInvoiceValueOfShipment,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  388. <td class="number">' . locale_number_format($TotalCostsToApportion,$_SESSION['CompanyRecord']['decimalplaces']) .'</td>
  389. </tr>';
  390. echo '<tr>
  391. <td colspan="6" class="number">' . _('Total Value of all variances on this shipment') . '</td>
  392. <td class="number">' . locale_number_format($TotalShiptVariance,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  393. </tr>';
  394. echo '</table>';
  395. echo '<br />
  396. <table colspan="2" width="95%">
  397. <tr>
  398. <td valign="top">'; // put this shipment charges side by side in a table (major table 2 cols)
  399. $sql = "SELECT suppliers.suppname,
  400. supptrans.suppreference,
  401. systypes.typename,
  402. supptrans.trandate,
  403. supptrans.rate,
  404. suppliers.currcode,
  405. shipmentcharges.stockid,
  406. shipmentcharges.value,
  407. supptrans.transno,
  408. supptrans.supplierno
  409. FROM supptrans INNER JOIN shipmentcharges
  410. ON shipmentcharges.transtype=supptrans.type
  411. AND shipmentcharges.transno=supptrans.transno
  412. INNER JOIN suppliers
  413. ON suppliers.supplierid=supptrans.supplierno
  414. INNER JOIN systypes ON systypes.typeid=supptrans.type
  415. WHERE shipmentcharges.stockid<>''
  416. AND shipmentcharges.shiptref='" . $_GET['SelectedShipment'] . "'
  417. ORDER BY supptrans.supplierno,
  418. supptrans.transno,
  419. shipmentcharges.stockid";
  420. $ChargesResult = DB_query($sql,$db);
  421. echo '<table cellpadding="2" colspan="6" class="selection">';
  422. echo '<tr>
  423. <th colspan="6"><font color="navy" size="3">' . _('Shipment Charges Against Products'). '</font></th>
  424. </tr>';
  425. $TableHeader = '<tr>
  426. <th>'. _('Supplier'). '</th>
  427. <th>'. _('Type'). '</th>
  428. <th>'. _('Ref'). '</th>
  429. <th>'. _('Date'). '</th>
  430. <th>'. _('Item'). '</th>
  431. <th>'. _('Local Amount'). '<br />'. _('Charged'). '</th>
  432. </tr>';
  433. echo $TableHeader;
  434. /*show the line items on the shipment with the value invoiced and shipt cost */
  435. $k=0; //row colour counter
  436. $RowCounter =0;
  437. $TotalItemShipmentChgs =0;
  438. while ($myrow=db_fetch_array($ChargesResult)) {
  439. if ($k==1){
  440. echo '<tr class="EvenTableRows">';
  441. $k=0;
  442. } else {
  443. echo '<tr class="OddTableRows">';
  444. $k=1;
  445. }
  446. echo '<td>' . $myrow['suppname'] . '</td>
  447. <td>' .$myrow['typename'] . '</td>
  448. <td>' . $myrow['suppreference'] . '</td>
  449. <td>' . ConvertSQLDate($myrow['trandate']) . '</td>
  450. <td>' . $myrow['stockid'] . '</td>
  451. <td class="number">' . locale_number_format($myrow['value'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  452. </tr>';
  453. $TotalItemShipmentChgs += $myrow['value'];
  454. }
  455. echo '<tr>
  456. <td colspan="5" class="number"><font color="blue"><b>'. _('Total Charges Against Shipment Items'). ':</b></font></td>
  457. <td class="number">' . locale_number_format($TotalItemShipmentChgs,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
  458. </tr>';
  459. echo '</table>';
  460. echo '</td><td valign="top">'; //major table
  461. /* Now the shipment freight/duty etc general charges */
  462. $sql = "SELECT suppliers.suppname,
  463. supptrans.suppreference,
  464. systypes.typename,
  465. supptrans.trandate,
  466. supptrans.rate,
  467. suppliers.currcode,
  468. shipmentcharges.stockid,
  469. shipmentcharges.value
  470. FROM supptrans INNER JOIN shipmentcharges
  471. ON shipmentcharges.transtype=supptrans.type
  472. AND shipmentcharges.transno=supptrans.transno
  473. INNER JOIN suppliers
  474. ON suppliers.supplierid=supptrans.supplierno
  475. INNER JOIN systypes
  476. ON systypes.typeid=supptrans.type
  477. WHERE shipmentcharges.stockid=''
  478. AND shipmentcharges.shiptref='" . $_GET['SelectedShipment'] . "'
  479. ORDER BY supptrans.supplierno,
  480. supptrans.transno";
  481. $ChargesResult = DB_query($sql,$db);
  482. echo '<table cellpadding="2" colspan="5" class="selection">';
  483. echo '<tr>
  484. <th colspan="6"><font color="navy" size="3">'._('General Shipment Charges').'</font></th>
  485. </tr>';
  486. $TableHeader = '<tr>
  487. <th>'. _('Supplier'). '</th>
  488. <th>'. _('Type'). '</th>
  489. <th>'. _('Ref'). '</th>
  490. <th>'. _('Date'). '</th>
  491. <th>'. _('Local Amount'). '<br />'. _('Charged'). '</th>
  492. </tr>';
  493. echo $TableHeader;
  494. /*show the line items on the shipment with the value invoiced and shipt cost */
  495. $k=0; //row colour counter
  496. $RowCounter =0;
  497. $TotalGeneralShipmentChgs =0;
  498. while ($myrow=db_fetch_array($ChargesResult)) {
  499. if ($k==1){
  500. echo '<tr class="EvenTableRows">';
  501. $k=0;
  502. } else {
  503. echo '<tr class="OddTableRows">';
  504. $k=1;
  505. }
  506. echo '<td>' . $myrow['suppname'] . '</td>
  507. <td>' .$myrow['typename'] . '</td>
  508. <td>' . $myrow['suppreference'] . '</td>
  509. <td>' . ConvertSQLDate($myrow['trandate']) . '</td>
  510. <td class="number">' . locale_number_format($myrow['value'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td></tr>';
  511. $TotalGeneralShipmentChgs += $myrow['value'];
  512. }
  513. echo '<tr>
  514. <td class="number" colspan="4"><font color="blue"><b>'. _('Total General Shipment Charges'). ':</b></font></td>
  515. <td class="number">' . locale_number_format($TotalGeneralShipmentChgs,$_SESSION['CompanyRecord']['decimalplaces']) . '</td></tr>';
  516. echo '</table>';
  517. echo '</td>
  518. </tr>
  519. </table>'; //major table close
  520. if ( isset($_GET['Close'])) { /* Only an opportunity to confirm user wishes to close */
  521. // if the page was called with Close=Yes then show options to confirm OK to c
  522. echo '<div class="centre">
  523. <form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) .'?SelectedShipment=' . $_GET['SelectedShipment'] . '">';
  524. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  525. if ($_SESSION['WeightedAverageCosting']==0){
  526. /* We are standard costing - so show the option to update costs - under W. Avg cost updates are implicit */
  527. echo _('Update Standard Costs') .':<select name="UpdateCost">
  528. <option selected value="Yes">'. _('Yes') . '</option>
  529. <option value="No">'. _('No') . '</option>
  530. </select>';
  531. }
  532. echo '<br />
  533. <br />
  534. <input type=submit name="Close" value="'. _('Confirm OK to Close'). '" />
  535. </form>
  536. </div>';
  537. }
  538. if ( isset($_POST['Close']) ){ /* OK do the shipment close journals */
  539. /*Inside a transaction need to:
  540. 1 . compare shipment costs against standard x qty received and take the variances off to the GL GRN supsense account and variances - this is done in the display loop
  541. 2. If UpdateCost=='Yes' then do the cost updates and GL entries.
  542. 3. Update the shipment to completed
  543. 1 and 2 done in the display loop above only 3 left*/
  544. /*also need to make sure the purchase order lines that were on this shipment are completed so no more can be received in against the order line */
  545. $result = DB_query("UPDATE purchorderdetails
  546. SET quantityord=quantityrecd,
  547. completed=1
  548. WHERE shiptref = '" . $_GET['SelectedShipment'] ."'",
  549. $db,
  550. _('Could not complete the purchase order lines on this shipment'),
  551. '',
  552. TRUE);
  553. $result = DB_query("UPDATE shipments SET closed=1 WHERE shiptref='" .$_GET['SelectedShipment']. "'",$db,_('Could not update the shipment to closed'),'',TRUE);
  554. $result = DB_Txn_Commit($db);
  555. echo '<br /><br />';
  556. prnMsg( _('Shipment'). ' ' . $_GET['SelectedShipment'] . ' ' . _('has been closed') );
  557. if ($_SESSION['CompanyRecord']['gllink_stock']==1) {
  558. echo '<br />';
  559. prnMsg ( _('All variances were posted to the general ledger') );
  560. }
  561. If ($_POST['UpdateCost']=='Yes'){
  562. echo '<br />';
  563. prnMsg ( _('All shipment items have had their standard costs updated') );
  564. }
  565. }
  566. include('includes/footer.inc');
  567. ?>