3 /* $Revision: 1.23 $ */
7 include('includes/session.inc');
8 $title = _('Customer Branches');
9 include('includes/header.inc');
11 if (isset($_GET['DebtorNo'])) {
12 $DebtorNo = strtoupper($_GET['DebtorNo']);
13 }elseif (isset($_POST['DebtorNo'])){
14 $DebtorNo = strtoupper($_POST['DebtorNo']);
17 if (!isset($DebtorNo)) {
18 prnMsg(_('This page must be called with the debtor code of the customer for whom you wish to edit the branches for').'. <BR>'._('When the pages is called from within the system this will always be the case').' <BR>'._('Select a customer first then select the link to add/edit/delete branches'),'warn');
19 include('includes/footer.inc');
24 if (isset($_GET['SelectedBranch'])){
25 $SelectedBranch = strtoupper($_GET['SelectedBranch']);
26 }elseif (isset($_POST['SelectedBranch'])){
27 $SelectedBranch = strtoupper($_POST['SelectedBranch']);
30 echo "<A HREF='" . $rootpath . '/SelectCustomer.php?' . SID . "'>" . _('Back to Customers') . '</A><BR>';
32 if (isset($_POST['submit'])) {
34 //initialise no input errors assumed initially before we test
37 /* actions to take once the user has clicked the submit button
38 ie the page has called itself with some user input */
40 //first off validate inputs sensible
42 $_POST['BranchCode'] = strtoupper($_POST['BranchCode']);
44 if (strstr($_POST['BranchCode'],"'") OR strstr($_POST['BranchCode'],'"') OR strstr($_POST['BranchCode'],'&')) {
46 prnMsg(_('The Branch code cannot contain any of the following characters')." - & \'",'error');
47 } elseif (strlen($_POST['BranchCode'])==0) {
49 prnMsg(_('The Branch code must be at least one character long'),'error');
50 } elseif (!Is_integer((int) $_POST['FwdDate'])) {
52 prnMsg(_('The date after which invoices are charged to the following month is expected to be a number and a recognised number has not been entered'),'error');
53 } elseif ($_POST['FwdDate'] >30) {
55 prnMsg(_('The date (in the month) after which invoices are charged to the following month should be a number less than 31'),'error');
56 } elseif (!Is_integer((int) $_POST['EstDeliveryDays'])) {
58 prnMsg(_('The estimated delivery days is expected to be a number and a recognised number has not been entered'),'error');
59 } elseif ($_POST['EstDeliveryDays'] >60) {
61 prnMsg(_('The estimated delivery days should be a number of days less than 60') . '. ' . _('A package can be delivered by seafreight anywhere in the world normally in less than 60 days'),'error');
64 if (!isset($_POST['EstDeliveryDays']) OR !is_numeric($_POST['EstDeliveryDays'])){
65 $_POST['EstDeliveryDays']=1;
67 if (!isset($_POST['FwdDate']) OR !is_numeric($_POST['FwdDate'])){
72 if (isset($SelectedBranch) AND $InputError !=1) {
74 /*SelectedBranch could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
76 $sql = "UPDATE custbranch SET brname = '" . DB_escape_string($_POST['BrName']) . "',
77 braddress1 = '" . DB_escape_string($_POST['BrAddress1']) . "',
78 braddress2 = '" . DB_escape_string($_POST['BrAddress2']) . "',
79 braddress3 = '" . DB_escape_string($_POST['BrAddress3']) . "',
80 braddress4 = '" . DB_escape_string($_POST['BrAddress4']) . "',
81 braddress5 = '" . DB_escape_string($_POST['BrAddress5']) . "',
82 braddress6 = '" . DB_escape_string($_POST['BrAddress6']) . "',
83 phoneno='" . DB_escape_string($_POST['PhoneNo']) . "',
84 faxno='" . DB_escape_string($_POST['FaxNo']) . "',
85 fwddate= " . $_POST['FwdDate'] . ",
86 contactname='" . DB_escape_string($_POST['ContactName']) . "',
87 salesman= '" . $_POST['Salesman'] . "',
88 area='" . $_POST['Area'] . "',
89 estdeliverydays =" . $_POST['EstDeliveryDays'] . ",
90 email='" . $_POST['Email'] . "',
91 taxgroupid=" . $_POST['TaxGroup'] . ",
92 defaultlocation='" . $_POST['DefaultLocation'] . "',
93 brpostaddr1 = '" . DB_escape_string($_POST['BrPostAddr1']) . "',
94 brpostaddr2 = '" . DB_escape_string($_POST['BrPostAddr2']) . "',
95 brpostaddr3 = '" . DB_escape_string($_POST['BrPostAddr3']) . "',
96 brpostaddr4 = '" . DB_escape_string($_POST['BrPostAddr4']) . "',
97 disabletrans=" . $_POST['DisableTrans'] . ",
98 defaultshipvia=" . $_POST['DefaultShipVia'] . ",
99 custbranchcode='" . $_POST['CustBranchCode'] ."',
100 deliverblind=" . $_POST['DeliverBlind'] . "
101 WHERE branchcode = '$SelectedBranch' AND debtorno='$DebtorNo'";
103 $msg = $_POST['BrName'] . ' '._('branch has been updated.');
105 } elseif ($InputError !=1) {
107 /*Selected branch is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Customer Branches form */
109 if ($_SESSION['vtiger_integration']==1){
112 /*Gets the Product ID for VTiger */
113 $result = DB_query('SELECT id FROM crmentity_seq',$db);
114 $myrow = DB_fetch_row($result);
115 $vtiger_accountid = $myrow[0] + 1;
117 $sql = "INSERT INTO custbranch (branchcode,
145 VALUES ('" . $_POST['BranchCode'] . "',
147 '" . DB_escape_string($_POST['BrName']) . "',
148 '" . DB_escape_string($_POST['BrAddress1']) . "',
149 '" . DB_escape_string($_POST['BrAddress2']) . "',
150 '" . DB_escape_string($_POST['BrAddress3']) . "',
151 '" . DB_escape_string($_POST['BrAddress4']) . "',
152 '" . DB_escape_string($_POST['BrAddress5']) . "',
153 '" . DB_escape_string($_POST['BrAddress6']) . "',
154 " . $_POST['EstDeliveryDays'] . ",
155 " . $_POST['FwdDate'] . ",
156 '" . $_POST['Salesman'] . "',
157 '" . DB_escape_string($_POST['PhoneNo']) . "',
158 '" . DB_escape_string($_POST['FaxNo']) . "',
159 '" . DB_escape_string($_POST['ContactName']) . "',
160 '" . $_POST['Area'] . "',
161 '" . DB_escape_string($_POST['Email']) . "',
162 " . $_POST['TaxGroup'] . ",
163 '" . $_POST['DefaultLocation'] . "',
164 '" . DB_escape_string($_POST['BrPostAddr1']) . "',
165 '" . DB_escape_string($_POST['BrPostAddr2']) . "',
166 '" . DB_escape_string($_POST['BrPostAddr3']) . "',
167 '" . DB_escape_string($_POST['BrPostAddr4']) . "',
168 " . $_POST['DisableTrans'] . ",
169 " . $_POST['DefaultShipVia'] . ",
170 '" . $_POST['CustBranchCode'] ."',
171 " . $_POST['DeliverBlind'] . ",
172 " . $vtiger_accountid . ")";
176 $sql = "INSERT INTO custbranch (branchcode,
203 VALUES ('" . $_POST['BranchCode'] . "',
205 '" . DB_escape_string($_POST['BrName']) . "',
206 '" . DB_escape_string($_POST['BrAddress1']) . "',
207 '" . DB_escape_string($_POST['BrAddress2']) . "',
208 '" . DB_escape_string($_POST['BrAddress3']) . "',
209 '" . DB_escape_string($_POST['BrAddress4']) . "',
210 '" . DB_escape_string($_POST['BrAddress5']) . "',
211 '" . DB_escape_string($_POST['BrAddress6']) . "',
212 " . $_POST['EstDeliveryDays'] . ",
213 " . $_POST['FwdDate'] . ",
214 '" . $_POST['Salesman'] . "',
215 '" . DB_escape_string($_POST['PhoneNo']) . "',
216 '" . DB_escape_string($_POST['FaxNo']) . "',
217 '" . DB_escape_string($_POST['ContactName']) . "',
218 '" . $_POST['Area'] . "',
219 '" . DB_escape_string($_POST['Email']) . "',
220 " . $_POST['TaxGroup'] . ",
221 '" . $_POST['DefaultLocation'] . "',
222 '" . DB_escape_string($_POST['BrPostAddr1']) . "',
223 '" . DB_escape_string($_POST['BrPostAddr2']) . "',
224 '" . DB_escape_string($_POST['BrPostAddr3']) . "',
225 '" . DB_escape_string($_POST['BrPostAddr4']) . "',
226 " . $_POST['DisableTrans'] . ",
227 " . $_POST['DefaultShipVia'] . ",
228 '" . $_POST['CustBranchCode'] ."',
229 " . $_POST['DeliverBlind'] . "
233 $msg = _('Customer branch').' '. $_POST['BrName'] . ' '._('has been added');
235 //run the SQL from either of the above possibilites
237 $ErrMsg = _('The branch record could not be inserted or updated because');
238 $result = DB_query($sql,$db, $ErrMsg);
241 if ($_SESSION['vtiger_integration']==1){
242 if (isset($SelectedBranch) AND $InputError !=1) {
244 /*Gets the accountid for VTiger */
245 $result = DB_query('SELECT vtiger_accountid FROM custbranch WHERE branchcode = "'.$SelectedBranch.'" ');
246 $myrow = DB_fetch_row($result);
247 $vtiger_accountid = $myrow[0]; // outputs current crmid
249 $today = date("YmdHis");
251 $sql = "UPDATE crmentity SET modifiedtime ='".$today."' WHERE crmid = '".$vtiger_accountid."'";
253 $ErrMsg = _('Could not update vtiger') . ' ' . $myrow[0] . ' ' . _('could not be added because');
254 $DbgMsg = _('Could not update vtiger') . ' ' . _('The SQL that was used to update the vtiger CRM entity');
255 $CRMResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
258 } elseif ($InputError !=1) {
260 $today = date("YmdHis");
261 $sql = "INSERT INTO crmentity (crmid,
268 VALUES('".$vtiger_accountid."',
276 $ErrMsg = _('The new vtiger CRM entiry could not be added because');
277 $DbgMsg = _('Could not add CRM') . ' ' . _('The SQL that was used to add the CRM entity');
278 $CRMResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
280 $sql = "UPDATE crmentity_seq SET id = ".$vtiger_accountid."";
281 $ErrMsg = _('CRM Sequence failed') . ' ' . $myrow[0] . ' ' . _('could not be added');
282 $DbgMsg = _('CRM Sequence failed') . ' ' . _('The SQL that was used to add the CRM Sequence');
283 $CRMseqResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
285 $sql = "INSERT INTO accountscf VALUES (".$vtiger_accountid.")";
287 $ErrMsg = _('insert into accountscf failed') . ' ' . $myrow[0] . ' ' . _('could not be added');
288 $DbgMsg = _('insert into accountscf failed') . ' ' . _('could not be added ');
289 $CRMseqResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
291 prnMsg(_('The new CRM entity has been created in vtiger for this new branch'),'success');
298 if (DB_error_no($db) ==0) {
299 prnMsg($msg,'success');
300 unset($_POST['BranchCode']);
301 unset($_POST['BrName']);
302 unset($_POST['BrAddress1']);
303 unset($_POST['BrAddress2']);
304 unset($_POST['BrAddress3']);
305 unset($_POST['BrAddress4']);
306 unset($_POST['BrAddress5']);
307 unset($_POST['BrAddress6']);
308 unset($_POST['EstDeliveryDays']);
309 unset($_POST['FwdDate']);
310 unset($_POST['Salesman']);
311 unset($_POST['PhoneNo']);
312 unset($_POST['FaxNo']);
313 unset($_POST['ContactName']);
314 unset($_POST['Area']);
315 unset($_POST['Email']);
316 unset($_POST['TaxGroup']);
317 unset($_POST['DefaultLocation']);
318 unset($_POST['DisableTrans']);
319 unset($_POST['BrPostAddr1']);
320 unset($_POST['BrPostAddr2']);
321 unset($_POST['BrPostAddr3']);
322 unset($_POST['BrPostAddr4']);
323 unset($_POST['DefaultShipVia']);
324 unset($_POST['CustBranchCode']);
325 unset($_POST['DeliverBlind']);
326 unset($SelectedBranch);
330 } elseif ($_GET['delete']) {
331 //the link to delete a selected record was clicked instead of the submit button
333 // PREVENT DELETES IF DEPENDENT RECORDS IN 'DebtorTrans'
335 $sql= "SELECT COUNT(*) FROM debtortrans WHERE debtortrans.branchcode='$SelectedBranch' AND debtorno = '$DebtorNo'";
336 $result = DB_query($sql,$db);
337 $myrow = DB_fetch_row($result);
339 prnMsg(_('Cannot delete this branch because customer transactions have been created to this branch') . '<BR>' .
340 _('There are').' ' . $myrow[0] . ' '._('transactions with this Branch Code'),'error');
343 $sql= "SELECT COUNT(*) FROM salesanalysis WHERE salesanalysis.custbranch='$SelectedBranch' AND salesanalysis.cust = '$DebtorNo'";
345 $result = DB_query($sql,$db);
347 $myrow = DB_fetch_row($result);
349 prnMsg(_('Cannot delete this branch because sales analysis records exist for it'),'error');
350 echo '<BR>'._('There are').' ' . $myrow[0] . ' '._('sales analysis records with this Branch Code/customer');
354 $sql= "SELECT COUNT(*) FROM salesorders WHERE salesorders.branchcode='$SelectedBranch' AND salesorders.debtorno = '$DebtorNo'";
355 $result = DB_query($sql,$db);
357 $myrow = DB_fetch_row($result);
359 prnMsg(_('Cannot delete this branch because sales orders exist for it') . '. ' . _('Purge old sales orders first'),'warn');
360 echo '<BR>'._('There are').' ' . $myrow[0] . ' '._('sales orders for this Branch/customer');
362 // Check if there are any users that refer to this branch code
363 $sql= "SELECT COUNT(*) FROM www_users WHERE www_users.branchcode='$SelectedBranch' AND www_users.customerid = '$DebtorNo'";
365 $result = DB_query($sql,$db);
366 $myrow = DB_fetch_row($result);
369 prnMsg(_('Cannot delete this branch because users exist that refer to it') . '. ' . _('Purge old users first'),'warn');
370 echo '<BR>'._('There are').' ' . $myrow[0] . ' '._('users referring to this Branch/customer');
373 $sql="DELETE FROM custbranch WHERE branchcode='" . $SelectedBranch . "' AND debtorno='" . $DebtorNo . "'";
374 $ErrMsg = _('The branch record could not be deleted') . ' - ' . _('the SQL server returned the following message');
375 $result = DB_query($sql,$db,$ErrMsg);
376 if (DB_error_no($db)==0){
377 prnMsg(_('Branch Deleted'),'success');
382 } //end ifs to test if the branch can be deleted
386 if (!isset($SelectedBranch)){
388 /* It could still be the second time the page has been run and a record has been selected for modification - SelectedBranch will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters then none of the above are true and the list of branches will be displayed with links to delete or edit each. These will call the same page again and allow update/input or deletion of the records*/
390 $sql = "SELECT debtorsmaster.name,
391 custbranch.branchcode,
393 salesman.salesmanname,
394 areas.areadescription,
399 taxgroups.taxgroupdescription,
400 custbranch.branchcode,
401 custbranch.disabletrans
407 WHERE custbranch.debtorno=debtorsmaster.debtorno
408 AND custbranch.area=areas.areacode
409 AND custbranch.salesman=salesman.salesmancode
410 AND custbranch.taxgroupid=taxgroups.taxgroupid
411 AND custbranch.debtorno = '$DebtorNo'";
413 $result = DB_query($sql,$db);
414 $myrow = DB_fetch_row($result);
418 echo '<BR><B>'._('Branches Defined for'). ' '. $DebtorNo . ' - ' . $myrow[0] . '</B>';
419 echo '<table border=1>';
421 echo "<tr><td class='tableheader'>"._('Code')."</td>
422 <td class='tableheader'>"._('Name')."</td>
423 <td class='tableheader'>"._('Contact')."</td>
424 <td class='tableheader'>"._('Salesman')."</td>
425 <td class='tableheader'>"._('Area')."</td>
426 <td class='tableheader'>"._('Phone No')."</td>
427 <td class='tableheader'>"._('Fax No')."</td>
428 <td class='tableheader'>"._('Email')."</td>
429 <td class='tableheader'>"._('Tax Group')."</td>
430 <td class='tableheader'>"._('Enabled?')."</td></tr>";
433 printf("<tr><td><font size=2>%s</td>
434 <td><font size=2>%s</td>
435 <td><font size=2>%s</font></td>
436 <td><font size=2>%s</font></td>
437 <td><font size=2>%s</font></td>
438 <td><font size=2>%s</font></td>
439 <td><font size=2>%s</font></td>
440 <td><font size=2><a href='Mailto:%s'>%s</a></font></td>
441 <td><font size=2>%s</font></td>
442 <td><font size=2>%s</font></td>
443 <td><font size=2><a href='%s?DebtorNo=%s&SelectedBranch=%s'>%s</font></td>
444 <td><font size=2><a href='%s?DebtorNo=%s&SelectedBranch=%s&delete=yes' onclick=\"return confirm('" . _('Are you sure you wish to delete this branch?') . "');\">%s</font></td></tr>",
455 ($myrow[11]?"No":"Yes"),
456 $_SERVER['PHP_SELF'],
458 urlencode($myrow[1]),
460 $_SERVER['PHP_SELF'],
462 urlencode($myrow[1]),
464 if ($myrow[11]){ $TotalDisable++; }
465 else { $TotalEnable++; }
467 } while ($myrow = DB_fetch_row($result));
468 //END WHILE LIST LOOP
470 echo '<b>'.$TotalEnable.'</b> Branches are enabled.<br>';
471 echo '<b>'.$TotalDisable.'</b> Branches are disabled.<br>';
472 echo '<b>'.($TotalEnable+$TotalDisable). '</b> Total Branches<br>';
474 $sql = "SELECT debtorsmaster.name,
482 WHERE debtorno = '$DebtorNo'";
484 $result = DB_query($sql,$db);
485 $myrow = DB_fetch_row($result);
486 echo '<B>'._('Branches Defined for').' - '.$myrow[0].'</B>';
487 $_POST['BranchCode'] = substr($DebtorNo,0,10);
488 $_POST['BrName'] = $myrow[0];
489 $_POST['BrAddress1'] = $myrow[1];
490 $_POST['BrAddress2'] = $myrow[2];
491 $_POST['BrAddress3'] = $myrow[3];
492 $_POST['BrAddress4'] = $myrow[4];
493 $_POST['BrAddress5'] = $myrow[5];
494 $_POST['BrAddress6'] = $myrow[6];
501 //end of ifs and buts!
503 if (isset($SelectedBranch)) {
504 echo '<Center><a href=' . $_SERVER['PHP_SELF'] . '?' . SID . 'DebtorNo=' . $DebtorNo. '>' . _('Show all branches defined for'). ' '. $DebtorNo . '</a></Center>';
508 if (! isset($_GET['delete'])) {
510 echo "<FORM METHOD='post' action=" . $_SERVER['PHP_SELF'] .'?' . SID . '>';
512 if (isset($SelectedBranch)) {
513 //editing an existing branch
515 $sql = "SELECT branchcode,
542 WHERE branchcode='$SelectedBranch'
543 AND debtorno='$DebtorNo'";
545 $result = DB_query($sql, $db);
546 $myrow = DB_fetch_array($result);
548 $_POST['BranchCode'] = $myrow['branchcode'];
549 $_POST['BrName'] = $myrow['brname'];
550 $_POST['BrAddress1'] = $myrow['braddress1'];
551 $_POST['BrAddress2'] = $myrow['braddress2'];
552 $_POST['BrAddress3'] = $myrow['braddress3'];
553 $_POST['BrAddress4'] = $myrow['braddress4'];
554 $_POST['BrAddress5'] = $myrow['braddress5'];
555 $_POST['BrAddress6'] = $myrow['braddress6'];
556 $_POST['BrPostAddr1'] = $myrow['brpostaddr1'];
557 $_POST['BrPostAddr2'] = $myrow['brpostaddr2'];
558 $_POST['BrPostAddr3'] = $myrow['brpostaddr3'];
559 $_POST['BrPostAddr4'] = $myrow['brpostaddr4'];
560 $_POST['EstDeliveryDays'] = $myrow['estdeliverydays'];
561 $_POST['FwdDate'] =$myrow['fwddate'];
562 $_POST['ContactName'] = $myrow['contactname'];
563 $_POST['Salesman'] =$myrow['salesman'];
564 $_POST['Area'] =$myrow['area'];
565 $_POST['PhoneNo'] =$myrow['phoneno'];
566 $_POST['FaxNo'] =$myrow['faxno'];
567 $_POST['Email'] =$myrow['email'];
568 $_POST['TaxGroup'] = $myrow['taxgroupid'];
569 $_POST['DisableTrans'] = $myrow['disabletrans'];
570 $_POST['DefaultLocation'] = $myrow['defaultlocation'];
571 $_POST['DefaultShipVia'] = $myrow['defaultshipvia'];
572 $_POST['CustBranchCode'] = $myrow['custbranchcode'];
573 $_POST['DeliverBlind'] = $myrow['deliverblind'];
575 echo "<INPUT TYPE=HIDDEN NAME='SelectedBranch' VALUE='" . $SelectedBranch . "'>";
576 echo "<INPUT TYPE=HIDDEN NAME='BranchCode' VALUE='" . $_POST['BranchCode'] . "'>";
577 echo "<CENTER><TABLE> <TR><TD>"._('Branch Code').':</TD><TD>';
578 echo $_POST['BranchCode'] . '</TD></TR>';
580 } else { //end of if $SelectedBranch only do the else when a new record is being entered
582 /* SETUP ANY $_GET VALUES THAT ARE PASSED. This really is just used coming from the Customers.php when a new customer is created.
583 Maybe should only do this when that page is the referrer?
585 if (isset($_GET['BranchCode'])){
586 $_POST['BranchCode'] = $_GET['BranchCode'];
588 if (isset($_GET['BrName'])){
589 $_POST['BrName'] = $_GET['BrName'];
591 if (isset($_GET['BrAddress1'])){
592 $_POST['BrAddress1'] = $_GET['BrAddress1'];
594 if (isset($_GET['BrAddress2'])){
595 $_POST['BrAddress2'] = $_GET['BrAddress2'];
597 if (isset($_GET['BrAddress3'])){
598 $_POST['BrAddress3'] = $_GET['BrAddress3'];
600 if (isset($_GET['BrAddress4'])){
601 $_POST['BrAddress4'] = $_GET['BrAddress4'];
603 if (isset($_GET['BrAddress5'])){
604 $_POST['BrAddress5'] = $_GET['BrAddress5'];
606 if (isset($_GET['BrAddress6'])){
607 $_POST['BrAddress6'] = $_GET['BrAddress6'];
610 echo '<CENTER><TABLE><TR><TD>'._('Branch Code').":</TD>
611 <TD><input type='Text' name='BranchCode' SIZE=12 MAXLENGTH=10 value=" . $_POST['BranchCode'] . '></TD></TR>';
612 $_POST['DeliverBlind'] = $_SESSION['DefaultBlindPackNote'];
615 //SQL to poulate account selection boxes
616 $sql = "SELECT salesmanname, salesmancode FROM salesman";
618 $result = DB_query($sql,$db);
620 if (DB_num_rows($result)==0){
622 prnMsg(_('There are no sales people defined as yet') . ' - ' . _('customer branches must be allocated to a sales person') . '. ' . _('Please use the link below to define at least one sales person'),'error');
623 echo "<BR><A HREF='$rootpath/SalesPeople.php?" . SID . "'>"._('Define Sales People').'</A>';
624 include('includes/footer.inc');
628 echo '<input type=HIDDEN name="DebtorNo" value="'. $DebtorNo . '">';
631 echo '<TR><TD>'._('Branch Name').':</TD>';
632 echo '<TD><input type="Text" name="BrName" SIZE=41 MAXLENGTH=40 value="'. $_POST['BrName'].'"></TD></TR>';
633 echo '<TR><TD>'._('Contact').':</TD>';
634 echo '<TD><input type="Text" name="ContactName" SIZE=41 MAXLENGTH=40 value="'. $_POST['ContactName'].'"></TD></TR>';
635 echo '<TR><TD>'._('Street Address 1').':</TD>';
636 echo '<TD><input type="Text" name="BrAddress1" SIZE=41 MAXLENGTH=40 value="'. $_POST['BrAddress1'].'"></TD></TR>';
637 echo '<TR><TD>'._('Street Address 2').':</TD>';
638 echo '<TD><input type="Text" name="BrAddress2" SIZE=41 MAXLENGTH=40 value="'. $_POST['BrAddress2'].'"></TD></TR>';
639 echo '<TR><TD>'._('Street Address 3').':</TD>';
640 echo '<TD><input type="Text" name="BrAddress3" SIZE=41 MAXLENGTH=40 value="'. $_POST['BrAddress3'].'"></TD></TR>';
641 echo '<TR><TD>'._('Street Address 4').':</TD>';
642 echo '<TD><input type="Text" name="BrAddress4" SIZE=31 MAXLENGTH=30 value="'. $_POST['BrAddress4'].'"></TD></TR>';
643 echo '<TR><TD>'._('Street Address 5').':</TD>';
644 echo '<TD><input type="Text" name="BrAddress5" SIZE=21 MAXLENGTH=20 value="'. $_POST['BrAddress5'].'"></TD></TR>';
645 echo '<TR><TD>'._('Street Address 6').':</TD>';
646 echo '<TD><input type="Text" name="BrAddress6" SIZE=16 MAXLENGTH=15 value="'. $_POST['BrAddress6'].'"></TD></TR>';
648 echo '<TR><TD>'._('Delivery Days').':</TD>';
649 echo '<TD><input type="Text" name="EstDeliveryDays" SIZE=4 MAXLENGTH=2 value='. $_POST['EstDeliveryDays'].'></TD></TR>';
650 echo '<TR><TD>'._('Forward Date After (day in month)').':</TD>';
651 echo '<TD><input type="Text" name="FwdDate" SIZE=4 MAXLENGTH=2 value='. $_POST['FwdDate'].'></TD></TR>';
653 echo '<TR><TD>'._('Salesperson').':</TD>';
654 echo '<TD><SELECT name="Salesman">';
656 while ($myrow = DB_fetch_array($result)) {
657 if ($myrow['salesmancode']==$_POST['Salesman']) {
658 echo '<OPTION SELECTED VALUE=';
660 echo '<OPTION VALUE=';
662 echo $myrow['salesmancode'] . '>' . $myrow['salesmanname'];
666 echo '</SELECT></TD></TR>';
668 DB_data_seek($result,0);
670 $sql = 'SELECT areacode, areadescription FROM areas';
671 $result = DB_query($sql,$db);
672 if (DB_num_rows($result)==0){
674 prnMsg(_('There are no areas defined as yet') . ' - ' . _('customer branches must be allocated to an area') . '. ' . _('Please use the link below to define at least one sales area'),'error');
675 echo "<BR><A HREF='$rootpath/Areas.php?" . SID . "'>"._('Define Sales Areas').'</A>';
676 include('includes/footer.inc');
680 echo '<TR><TD>'._('Sales Area').':</TD>';
681 echo '<TD><SELECT name="Area">';
682 while ($myrow = DB_fetch_array($result)) {
683 if ($myrow['areacode']==$_POST['Area']) {
684 echo '<OPTION SELECTED VALUE=';
686 echo '<OPTION VALUE=';
688 echo $myrow['areacode'] . '>' . $myrow['areadescription'];
693 echo '</SELECT></TD></TR>';
694 DB_data_seek($result,0);
696 $sql = 'SELECT loccode, locationname FROM locations';
697 $result = DB_query($sql,$db);
699 if (DB_num_rows($result)==0){
701 prnMsg(_('There are no stock locations defined as yet') . ' - ' . _('customer branches must refer to a default location where stock is normally drawn from') . '. ' . _('Please use the link below to define at least one stock location'),'error');
702 echo "<BR><A HREF='$rootpath/Locations.php?" . SID . "'>"._('Define Stock Locations').'</A>';
703 include('includes/footer.inc');
707 echo '<TR><TD>'._('Draw Stock From').':</TD>';
708 echo '<TD><SELECT name="DefaultLocation">';
710 while ($myrow = DB_fetch_array($result)) {
711 if ($myrow['loccode']==$_POST['DefaultLocation']) {
712 echo '<OPTION SELECTED VALUE=';
714 echo '<OPTION VALUE=';
716 echo $myrow['loccode'] . '>' . $myrow['locationname'];
720 echo '</SELECT></TD></TR>';
721 echo '<TR><TD>'._('Phone Number').':</TD>';
722 echo '<TD><input type="Text" name="PhoneNo" SIZE=22 MAXLENGTH=20 value="'. $_POST['PhoneNo'].'"></TD></TR>';
724 echo '<TR><TD>'._('Fax Number').':</TD>';
725 echo '<TD><input type="Text" name="FaxNo" SIZE=22 MAXLENGTH=20 value="'. $_POST['FaxNo'].'"></TD></TR>';
728 echo '<TR><TD><a href="Mailto:'. $_POST['Email'].'">'._('Email').':</a></TD>';
729 echo '<TD><input type="Text" name="Email" SIZE=56 MAXLENGTH=55 value="'. $_POST['Email'].'"></TD></TR>';
731 echo '<TR><TD>'._('Tax Group').':</TD>';
732 echo '<TD><SELECT name="TaxGroup">';
734 DB_data_seek($result,0);
736 $sql = 'SELECT taxgroupid, taxgroupdescription FROM taxgroups';
737 $result = DB_query($sql,$db);
739 while ($myrow = DB_fetch_array($result)) {
740 if ($myrow['taxgroupid']==$_POST['TaxGroup']) {
741 echo '<OPTION SELECTED VALUE=';
743 echo '<OPTION VALUE=';
745 echo $myrow['taxgroupid'] . '>' . $myrow['taxgroupdescription'];
749 echo '</SELECT></TD></TR>';
750 echo '<TR><TD>'._('Disable transactions on this branch').":</TD><TD><SELECT NAME='DisableTrans'>";
751 if ($_POST['DisableTrans']==0){
752 echo '<OPTION SELECTED VALUE=0>' . _('Enabled');
753 echo '<OPTION VALUE=1>' . _('Disabled');
755 echo '<OPTION SELECTED VALUE=1>' . _('Disabled');
756 echo '<OPTION VALUE=0>' . _('Enabled');
759 echo ' </SELECT></TD></TR>';
761 echo '<TR><TD>'._('Default freight company').":</TD><TD><SELECT name='DefaultShipVia'>";
762 $SQL = 'SELECT shipper_id, shippername FROM shippers';
763 $ShipperResults = DB_query($SQL,$db);
764 while ($myrow=DB_fetch_array($ShipperResults)){
765 if ($myrow['shipper_id']==$_POST['DefaultShipVia']){
766 echo '<OPTION SELECTED VALUE=' . $myrow['shipper_id'] . '>' . $myrow['shippername'];
768 echo '<OPTION VALUE=' . $myrow['shipper_id'] . '>' . $myrow['shippername'];
772 echo '</SELECT></TD></TR>';
774 /* This field is a default value that will be used to set the value
775 on the sales order which will control whether or not to display the
776 company logo and address on the packlist */
777 echo '<TR><TD>' . _('Default Packlist') . ":</TD><TD><SELECT NAME='DeliverBlind'>";
778 for ($p = 1; $p <= 2; $p++) {
779 echo '<OPTION VALUE=' . $p;
780 if ($p == $_POST['DeliverBlind']) {
787 echo _('Show company details and logo'); break;
789 echo _('Hide company details and logo'); break;
792 echo '</SELECT></TD></TR>';
794 echo '<TR><TD>'._('Postal Address 1').':</TD>';
795 echo '<TD><input type="Text" name="BrPostAddr1" SIZE=41 MAXLENGTH=40 value="'. $_POST['BrPostAddr1'].'"></TD></TR>';
796 echo '<TR><TD>'._('Postal Address 2').':</TD>';
797 echo '<TD><input type="Text" name="BrPostAddr2" SIZE=41 MAXLENGTH=40 value="'. $_POST['BrPostAddr2'].'"></TD></TR>';
798 echo '<TR><TD>'._('Postal Address 3').':</TD>';
799 echo '<TD><input type="Text" name="BrPostAddr3" SIZE=31 MAXLENGTH=30 value="'. $_POST['BrPostAddr3'].'"></TD></TR>';
800 echo '<TR><TD>'._('Postal Address 4').':</TD>';
801 echo '<TD><input type="Text" name="BrPostAddr4" SIZE=21 MAXLENGTH=20 value="'. $_POST['BrPostAddr4'].'"></TD></TR>';
802 echo '<TR><TD>'._('Customers Internal Branch Code (EDI)').':</TD>';
803 echo '<TD><input type="Text" name="CustBranchCode" SIZE=31 MAXLENGTH=30 value="'. $_POST['CustBranchCode'].'"></TD></TR>';
806 echo '<CENTER><input type="Submit" name="submit" value='._('Enter Information').'>';
810 } //end if record deleted no point displaying form to add record
812 include('includes/footer.inc');