1<?php
2
3
4/*The supplier transaction uses the SuppTrans class to hold the information about the invoice
5the SuppTrans class contains an array of Shipts objects - containing details of all shipment charges for invoicing
6Shipment charges are posted to the debit of GRN suspense if the Creditors - GL link is on
7This is cleared against credits to the GRN suspense when the products are received into stock and any
8purchase price variance calculated when the shipment is closed */
9
10include('includes/DefineSuppTransClass.php');
11
12/* Session started here for password checking and authorisation level check */
13include('includes/session.php');
14
15$Title = _('Shipment Charges or Credits');
16
17include('includes/header.php');
18
19if ($_SESSION['SuppTrans']->InvoiceOrCredit == 'Invoice'){
20	echo '<a href="' . $RootPath . '/SupplierInvoice.php">' . _('Back to Invoice Entry') . '</a>';
21} else {
22	echo '<a href="' . $RootPath . '/SupplierCredit.php">' . _('Back to Credit Note Entry') . '</a>';
23}
24
25if (!isset($_SESSION['SuppTrans'])){
26	prnMsg(_('Shipment charges or credits are entered against supplier invoices or credit notes respectively') . '. ' . _('To enter supplier transactions the supplier must first be selected from the supplier selection screen') . ', ' . _('then the link to enter a supplier invoice or credit note must be clicked on'),'info');
27	echo '<br /><a href="' . $RootPath . '/SelectSupplier.php">' . _('Select a supplier') . '</a>';
28	exit;
29	/*It all stops here if there aint no supplier selected and invoice/credit initiated ie $_SESSION['SuppTrans'] started off*/
30}
31
32/*If the user hit the Add to transaction button then process this first before showing  all GL codes on the invoice otherwise it wouldnt show the latest addition*/
33
34if (isset($_POST['AddShiptChgToInvoice'])){
35
36	$InputError = False;
37	if ($_POST['ShiptRef'] == ''){
38		if ($_POST['ShiptSelection']==''){
39			prnMsg(_('Shipment charges must reference a shipment. It appears that no shipment has been entered'),'error');
40			$InputError = True;
41		} else {
42			$_POST['ShiptRef'] = $_POST['ShiptSelection'];
43		}
44	} else {
45		$result = DB_query("SELECT shiptref FROM shipments WHERE shiptref='". $_POST['ShiptRef'] . "'");
46		if (DB_num_rows($result)==0) {
47			prnMsg(_('The shipment entered manually is not a valid shipment reference. If you do not know the shipment reference, select it from the list'),'error');
48			$InputError = True;
49		}
50	}
51
52	if (!is_numeric(filter_number_format($_POST['Amount']))){
53		prnMsg(_('The amount entered is not numeric') . '. ' . _('This shipment charge cannot be added to the invoice'),'error');
54		$InputError = True;
55	}
56
57	if ($InputError == False){
58		$_SESSION['SuppTrans']->Add_Shipt_To_Trans($_POST['ShiptRef'],
59													filter_number_format($_POST['Amount']));
60		unset($_POST['ShiptRef']);
61		unset($_POST['Amount']);
62	}
63}
64
65if (isset($_GET['Delete'])){
66
67	$_SESSION['SuppTrans']->Remove_Shipt_From_Trans($_GET['Delete']);
68}
69
70/*Show all the selected ShiptRefs so far from the SESSION['SuppInv']->Shipts array */
71if ($_SESSION['SuppTrans']->InvoiceOrCredit=='Invoice'){
72	echo '<p class="page_title_text">' .  _('Shipment charges on Invoice') . ' ';
73} else {
74	echo '<p class="page_title_text">' . _('Shipment credits on Credit Note') . ' ';
75}
76echo $_SESSION['SuppTrans']->SuppReference . ' ' ._('From') . ' ' . $_SESSION['SuppTrans']->SupplierName;
77echo '</p>';
78echo '<table cellpadding="2" class="selection">';
79$TableHeader = '<tr><th>' . _('Shipment') . '</th>
80		<th>' . _('Amount') . '</th></tr>';
81echo $TableHeader;
82
83$TotalShiptValue = 0;
84
85foreach ($_SESSION['SuppTrans']->Shipts as $EnteredShiptRef){
86
87	echo '<tr><td>' . $EnteredShiptRef->ShiptRef . '</td>
88		<td class="number">' . locale_number_format($EnteredShiptRef->Amount,2) . '</td>
89		<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?Delete=' . $EnteredShiptRef->Counter . '">' . _('Delete') . '</a></td></tr>';
90
91	$TotalShiptValue = $TotalShiptValue + $EnteredShiptRef->Amount;
92
93}
94
95echo '<tr>
96	<td class="number">' . _('Total') . ':</td>
97	<td class="number">' . locale_number_format($TotalShiptValue,2) . '</td>
98</tr>
99</table><br />';
100
101/*Set up a form to allow input of new Shipment charges */
102echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
103echo '<div>';
104echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
105
106if (!isset($_POST['ShiptRef'])) {
107	$_POST['ShiptRef']='';
108}
109echo '<table class="selection">';
110echo '<tr>
111		<td>' . _('Shipment Reference') . ':</td>
112		<td><input class="integer" pattern="[1-9][\d]{0,10}" title="'._('The shiment Ref should be positive integer').'" placeholder="'._('positive integer').'" name="ShiptRef" size="12" maxlength="11" value="' .  $_POST['ShiptRef'] . '" /></td>
113	</tr>';
114echo '<tr>
115		<td>' . _('Shipment Selection') . ':
116			<br /> ' . _('If you know the code enter it above') . '
117			<br />' . _('otherwise select the shipment from the list') . '</td>
118		<td><select name="ShiptSelection">';
119
120$sql = "SELECT shiptref,
121				vessel,
122				eta,
123				suppname
124			FROM shipments INNER JOIN suppliers
125				ON shipments.supplierid=suppliers.supplierid
126			WHERE closed='0'";
127
128$result = DB_query($sql);
129
130while ($myrow = DB_fetch_array($result)) {
131	if (isset($_POST['ShiptSelection']) and $myrow['shiptref']==$_POST['ShiptSelection']) {
132		echo '<option selected="selected" value="';
133	} else {
134		echo '<option value="';
135	}
136	echo $myrow['shiptref'] . '">' . $myrow['shiptref'] . ' - ' . $myrow['vessel'] . ' ' . _('ETA') . ' ' . ConvertSQLDate($myrow['eta']) . ' ' . _('from') . ' ' . $myrow['suppname']  . '</option>';
137}
138
139echo '</select></td>
140	</tr>';
141
142if (!isset($_POST['Amount'])) {
143	$_POST['Amount']=0;
144}
145echo '<tr>
146		<td>' . _('Amount') . ':</td>
147		<td><input type="text"  class="number" required="required" title="'._('The input must be non zero number').'" placeholder="'._('Non zero number').'" name="Amount" size="12" maxlength="11" value="' .  locale_number_format($_POST['Amount'],$_SESSION['SuppTrans']->CurrDecimalPlaces) . '" /></td>
148	</tr>
149	</table>';
150
151echo '<br />
152	<div class="centre">
153		<input type="submit" name="AddShiptChgToInvoice" value="' . _('Enter Shipment Charge') . '" />
154	</div>
155    </div>
156	</form>';
157
158include('includes/footer.php');
159?>
160