3 /* contributed by Chris Bice */
6 include('includes/session.inc');
7 $title = _('Inventory Location Transfer Shipment');
8 include('includes/header.inc');
9 include('includes/SQL_CommonFunctions.inc');
11 If (isset($_POST['Submit']) OR isset($_POST['EnterMoreItems'])){
12 /*Trap any errors in input */
14 $InputError = False; /*Start off hoping for the best */
16 //Make sure this Transfer has not already been entered... aka one way around the refresh & insert new records problem
17 $result = DB_query("SELECT * FROM loctransfers WHERE reference='" . $_POST['Trf_ID'] . "'",$db);
18 if (DB_num_rows($result)!=0){
20 $ErrorMessage = _('This transaction has already been entered') . '. ' . _('Please start over now').'<BR>';
21 unset($_POST['submit']);
22 unset($_POST['EnterMoreItems']);
23 for ($i=$_POST['LinesCounter']-10;$i<$_POST['LinesCounter'];$i++
){
24 unset($_POST['StockID' . $i]);
25 unset($_POST['StockQTY' . $i]);
28 for ($i=$_POST['LinesCounter']-10;$i<$_POST['LinesCounter'];$i++
){
30 $_POST['StockID' . $i]=trim(strtoupper($_POST['StockID' . $i]));
31 if ($_POST['StockID' . $i]!=''){
32 $result = DB_query("SELECT COUNT(stockid) FROM stockmaster WHERE stockid='" . $_POST['StockID' . $i] . "'",$db);
33 $myrow = DB_fetch_row($result);
36 $ErrorMessage .= _('The part code entered of'). ' ' . $_POST['StockID' . $i] . ' '. _('is not set up in the database') . '. ' . _('Only valid parts can be entered for transfers'). '<BR>';
37 $_POST['LinesCounter'] -= 10;
39 DB_free_result( $result );
40 if (!is_numeric($_POST['StockQTY' . $i])){
42 $ErrorMessage .= _('The quantity entered of'). ' ' . $_POST['StockQTY' . $i] . ' '. _('for part code'). ' ' . $_POST['StockID' . $i] . ' '. _('is not numeric') . '. ' . _('The quantity entered for transfers is expected to be numeric').'<BR>';
43 $_POST['LinesCounter'] -= 10;
45 if ($_POST['StockQTY' . $i] <= 0){
47 $ErrorMessage .= _('The quantity entered for').' '. $_POST['StockID' . $i] . ' ' . _('is less than or equal to 0') . '. ' . _('Please correct this or remove the item').'<BR>';
50 // Only if stock exist at this location
51 $result = DB_query("SELECT quantity FROM locstock WHERE stockid='" . $_POST['StockID' . $i] . "' and loccode='".$_POST['FromStockLocation']."'",$db);
52 $myrow = DB_fetch_row($result);
55 $ErrorMessage .= _('The part code entered of'). ' ' . $_POST['StockID' . $i] . ' '. _('does not have stock available for transfer.') . '.<BR>';
56 $_POST['LinesCounter'] -= 10;
58 DB_free_result( $result );
61 }//for all LinesCounter
62 if ($TotalItems == 0){
64 $ErrorMessage .= _('You must enter at least 1 Stock Item to transfer').'<BR>';
67 /*Ship location and Receive location are different */
68 If ($_POST['FromStockLocation']==$_POST['ToStockLocation']){
70 $ErrorMessage .= _('The transfer must have a different location to receive into and location sent from');
74 if(isset($_POST['Submit']) AND $InputError==False){
76 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('Unable to BEGIN Location Transfer transaction');
77 DB_query('BEGIN',$db, $ErrMsg);
78 for ($i=0;$i < $_POST['LinesCounter'];$i++
){
80 if($_POST['StockID' . $i] != ""){
81 $sql = "INSERT INTO loctransfers (reference,
87 VALUES ('" . $_POST['Trf_ID'] . "',
88 '" . $_POST['StockID' . $i] . "',
89 '" . $_POST['StockQTY' . $i] . "',
90 '" . Date('Y-m-d') . "',
91 '" . $_POST['FromStockLocation'] ."',
92 '" . $_POST['ToStockLocation'] . "')";
93 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('Unable to enter Location Transfer record for'). ' '.$_POST['StockID' . $i];
94 $resultLocShip = DB_query($sql,$db, $ErrMsg);
97 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('Unable to COMMIT Location Transfer transaction');
98 DB_query('BEGIN',$db, $ErrMsg);
100 prnMsg( _('The inventory transfer records have been created successfully'),'success');
101 echo '<P><A HREF="'.$rootpath.'/PDFStockLocTransfer.php?' . SID
. 'TransferNo=' . $_POST['Trf_ID'] . '">'.
102 _('Print the Transfer Docket'). '</A>';
103 unset($_SESSION['DispatchingTransfer']);
104 unset($_SESSION['Transfer']);
108 //Get next Inventory Transfer Shipment Reference Number
109 if (isset($_GET['Trf_ID'])){
110 $Trf_ID = $_GET['Trf_ID'];
111 } elseif (isset($_POST['Trf_ID'])){
112 $Trf_ID = $_POST['Trf_ID'];
116 $Trf_ID = GetNextTransNo(16,$db);
119 If ($InputError==true){
121 prnMsg($ErrorMessage, 'error');
126 echo '<HR><FORM ACTION="' . $_SERVER['PHP_SELF'] . '?'. SID
. '" METHOD=POST>';
128 echo '<input type=HIDDEN NAME="Trf_ID" VALUE="' . $Trf_ID . '"><h2>'. _('Inventory Location Transfer Shipment Reference').' # '. $Trf_ID. '</h2>';
130 $sql = 'SELECT loccode, locationname FROM locations';
131 $resultStkLocs = DB_query($sql,$db);
132 echo _('From Stock Location').':<SELECT name="FromStockLocation">';
133 while ($myrow=DB_fetch_array($resultStkLocs)){
134 if (isset($_POST['FromStockLocation'])){
135 if ($myrow['loccode'] == $_POST['FromStockLocation']){
136 echo '<OPTION SELECTED Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
138 echo '<OPTION Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
140 } elseif ($myrow['loccode']==$_SESSION['UserStockLocation']){
141 echo '<OPTION SELECTED Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
142 $_POST['FromStockLocation']=$myrow['loccode'];
144 echo '<OPTION Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
149 DB_data_seek($resultStkLocs,0); //go back to the start of the locations result
150 echo _('To Stock Location').':<SELECT name="ToStockLocation">';
151 while ($myrow=DB_fetch_array($resultStkLocs)){
152 if (isset($_POST['ToStockLocation'])){
153 if ($myrow['loccode'] == $_POST['ToStockLocation']){
154 echo '<OPTION SELECTED Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
156 echo '<OPTION Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
158 } elseif ($myrow['loccode']==$_SESSION['UserStockLocation']){
159 echo '<OPTION SELECTED Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
160 $_POST['ToStockLocation']=$myrow['loccode'];
162 echo '<OPTION Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
165 echo '</SELECT><BR>';
167 echo '<CENTER><TABLE>';
169 $tableheader = '<TR><TD class="tableheader">'. _('Item Code'). '</TD><TD class="tableheader">'. _('Quantity'). '</TD></TR>';
172 $k=0; /* row counter */
173 if(isset($_POST['LinesCounter'])){
175 for ($i=0;$i < $_POST['LinesCounter'] AND $_POST['StockID' . $i] !='';$i++
){
182 <TD><input type=text name="StockID' . $i .'" size=21 maxlength=20 Value="' . $_POST['StockID' . $i] . '"></TD>
183 <TD><input type=text name="StockQTY' . $i .'" size=5 maxlength=4 Value="' . $_POST['StockQTY' . $i] . '"></TD>
189 // $i is incremented an extra time, so 9 to get 10...
194 <td><input type=text name="StockID' . $i .'" size=21 maxlength=20 Value="' . $_POST['StockID' . $i] . '"></td>
195 <td><input type=text name="StockQTY' . $i .'" size=5 maxlength=4 Value="' . $_POST['StockQTY' . $i] . '"></td>
201 <input type=hidden name="LinesCounter" value='. $i .'><INPUT TYPE=SUBMIT NAME="EnterMoreItems" VALUE="'. _('Add More Items'). '"><INPUT TYPE=SUBMIT NAME="Submit" VALUE="'. _('Create Transfer Shipment'). '"><BR><HR>';
202 echo '</FORM></CENTER>';
203 include('includes/footer.inc');