function details($_POST, $error = "") { extract($_REQUEST); $fields = array(); $fields["deptid"] = 2; $fields["cusnum"] = 0; $fields["telno"] = ""; $fields["cordno"] = ""; $fields["des"] = ""; $fields["pinv_day"] = date("d"); $fields["pinv_month"] = date("m"); $fields["pinv_year"] = date("Y"); $fields["vatinc_yes"] = "checked"; $fields["vatinc_no"] = ""; $fields["vat14"] = AT14; $fields["vat"] = "0.00"; $fields["total"] = "0.00"; $fields["rounding"] = ""; $fields["nhifrm_year"] = date("Y"); $fields["nhifrm_month"] = date("m"); $fields["nhifrm_day"] = date("d"); $fields["nhito_year"] = date("Y"); $fields["nhito_month"] = date("m"); $fields["nhito_day"] = date("d"); $fields["client_collect"] = ""; $fields["collect"] = ""; $fields["deliver"] = ""; $fields["deposit_amt"] = "0.00"; $fields["deposit_type"] = "CSH"; $fields["custom_txt"] = ""; $fields["monthly"] = false; $fields["bk_asset"] = 0; // 30 Asset $fields["bk_id"] = 0; $fields["reprint"] = 0; extract($fields, EXTR_SKIP); if (isset($bk_from)) { list($nhifrm_year, $nhifrm_month, $nhifrm_day) = explode("-", $bk_from); } if (isset($bk_to)) { list($nhito_year, $nhito_month, $nhito_day) = explode("-", $bk_to); } $subtot = 0; if (isset($hirenewBtn)) { newHire($_POST); } // Get us an invoice id if (!isset($invid)) { $invid = create_dummy($deptid); } else { $sql = "SELECT cusnum FROM hire.hire_invoices WHERE invid='{$invid}'"; $cn_rslt = db_exec($sql) or errDie("Unable to retrieve invoices."); $cusnum = pg_fetch_result($cn_rslt, 0); updateTotals($invid); } $ind_ccol = ""; $ind_col = ""; $ind_del = ""; $collect_ar = array(); if (!empty($client_collect)) { $collect_ar[] = "Client Collect"; } if (!empty($collect)) { $collect_ar[] = "Collect"; } if (!empty($deliver)) { $collect_ar[] = "Deliver"; } if (empty($client_collect) && empty($collect) && empty($deliver)) { $client_collect = "checked"; $collect_ar[] = "Client Collect"; } $collection = implode(", ", $collect_ar); if (empty($monthly)) { $sql = "SELECT *, extract('epoch' FROM expected) AS e_exp, extract('epoch' FROM to_date) AS e_to FROM hire.hire_invitems WHERE invid='{$invid}'"; $item_rslt = db_exec($sql) or errDie("Unable to retrieve items."); while ($item_data = pg_fetch_array($item_rslt)) { if (!empty($item_data["expected"])) { if ($item_data["e_to"] > time()) { $item_data["expected"] = date("Y-m-t", $item_data["e_to"]); } else { if ($item_data["e_exp"] < time()) { $item_data["expected"] = date("Y-m-t"); } } $sql = "\r\n\t\t\t\t\tUPDATE hire.hire_invitems \r\n\t\t\t\t\tSET from_date='{$item_data['to_date']}', to_date='{$item_data['expected']}', expected=NULL \r\n\t\t\t\t\tWHERE id='{$item_data['id']}'"; db_exec($sql) or errDie("Unable to update invoice."); } } } // Retrieve the actual invoice $sql = "SELECT * FROM hire.hire_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $inv_rslt = db_exec($sql) or errDie("Unable to get invoice information"); $inv_data = pg_fetch_array($inv_rslt); if ($cusnum == 0) { $cusnum = $inv_data["cusnum"]; } if (empty($cordno)) { $cordno = $inv_data["cordno"]; } $pinv_date = explode("-", $inv_data["odate"]); $pinv_year = $pinv_date[0]; $pinv_month = $pinv_date[1]; $pinv_day = $pinv_date[2]; // Create the dropdowns --------------------------------------------------- // Retrieve departments $sql = "SELECT * FROM exten.departments ORDER BY deptname ASC"; $dept_rslt = db_exec($sql) or errDie("Unable to retrieve departments."); // Create departments dropdown $dept_sel = "<select name='deptid' style='width: 100%'>"; while ($dept_data = pg_fetch_array($dept_rslt)) { $dept_sel .= "<option value='{$dept_data['deptid']}'>{$dept_data['deptname']}</option>"; } $dept_sel .= "</select>"; // Check customer basis if ($cusnum > 0) { checkCustBasis($cusnum); } // Retrieve customers $sql = "SELECT * FROM cubit.customers ORDER BY surname ASC"; $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customers."); // Create customers dropdown if (empty($cusnum)) { $cust_sel = "\r\n\t\t\t<select name='cusnum' style='width: 100%' onchange='javascript:document.form.submit()'>\r\n\t\t\t\t<option value='0'>[None]</option>"; while ($cust_data = pg_fetch_array($cust_rslt)) { $sel = fsel(isset($cusnum) && $cusnum == $cust_data["cusnum"]); $cust_sel .= "<option value='{$cust_data['cusnum']}' {$sel}>{$cust_data['surname']}</option>"; } $cust_sel .= "</select>"; } else { $sql = "SELECT * FROM cubit.customers WHERE cusnum='{$cusnum}'"; $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customer."); $cust_data = pg_fetch_array($cust_rslt); $cust_sel = $cust_data["surname"]; } // Retrieve sales people $sql = "SELECT * FROM exten.salespeople ORDER BY salesp ASC"; $salesp_rslt = db_exec($sql) or errDie("Unable to retrieve sales people."); // Create sales people dropdown $salesp_sel = "<select name='salespid' style='width: 100%'>"; while ($salesp_data = pg_fetch_array($salesp_rslt)) { $salesp_sel .= "<option value='{$salesp_data['salespid']}'>{$salesp_data['salesp']}</option>"; } $salesp_sel .= "</select>"; // Deposit Options $deposit_list = array("CSH" => "Cash", "CHQ" => "Cheque", "CRD" => "Credit Card"); // Create the deposit dropdown $deposit_sel = "<select name='deposit_type'>"; foreach ($deposit_list as $key => $value) { if ($inv_data["deposit_type"] == $key) { $sel = "selected"; } else { $sel = ""; } $deposit_sel .= "<option value='{$key}' {$sel}>{$value}</option>"; } $deposit_sel .= "</select>"; // Items Display ------------------------------------------------------- $basis_list = array("per_day" => "Per Day", "per_hour" => "Per Hour", "per_week" => "Per Week"); // Retrieve items $sql = "SELECT * FROM hire.hire_invitems WHERE invid='{$invid}' ORDER BY id ASC"; $items_rslt = db_exec($sql) or errDie("Unable to retrieve items."); $items_out = ""; $temp_assets = array(); while ($items_data = pg_fetch_array($items_rslt)) { $i = $items_data["id"]; // Create the basis display $basis_disp = $basis_list[$items_data["basis"]]; // Retrieve assets $sql = "SELECT * FROM cubit.assets WHERE id='{$items_data['asset_id']}'"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets."); $ad = pg_fetch_array($asset_rslt); // Retrieve asset group $sql = "SELECT * FROM cubit.assetgrp WHERE grpid='{$ad['grpid']}'"; $agrp_rslt = db_exec($sql) or errDie("Unable to retrieve asset group."); $agrp_data = pg_fetch_array($agrp_rslt); if ($agrp_data["grpname"] == "Temporary Asset") { $temp_assets[] = $agrp_data[$ad["id"]]; } // if ($ad["serial"] == "CUBIT::-QTY-") { // $asset_disp = "$ad[des]"; // } else { // $asset_disp = "$ad[des] ($ad[serial])"; // } $asset_disp = $ad["des"] . " " . getSerial($ad["id"], 1); $subtot += $items_data["amt"]; //*$items_data["qty"]; if ($items_data["basis"] == "per_hour") { $from_disp = "Hours: {$items_data['hours']}"; $to_disp = ""; } else { if ($items_data["basis"] == "per_day") { $mfrm_date = $items_data["from_date"]; $mfrm_date = explode("-", $mfrm_date); $mfrm_year[$i] = $mfrm_date[0]; $mfrm_month[$i] = $mfrm_date[1]; $mfrm_day[$i] = $mfrm_date[2]; $mto_date = $items_data["to_date"]; $mto_date = explode("-", $mto_date); $mto_year[$i] = $mto_date[0]; $mto_month[$i] = $mto_date[1]; $mto_day[$i] = $mto_date[2]; $from_disp = mkDateSelectA("mfrm", $i, $mfrm_year[$i], $mfrm_month[$i], $mfrm_day[$i]); $to_disp = mkDateSelectA("mto", $i, $mto_year[$i], $mto_month[$i], $mto_day[$i]); // $from_disp = " // <input type='hidden' name='mfrm_year[$i]' value='$mfrm_year[$i]' /> // <input type='hidden' name='mfrm_month[$i]' value='$mfrm_month[$i]' /> // <input type='hidden' name='mfrm_day[$i]' value='$mfrm_day[$i]' /> // $mfrm_day[$i]-$mfrm_month[$i]-$mfrm_year[$i]"; // $to_disp = " // <input type='hidden' name='mto_year[$i]' value='$mto_year[$i]' /> // <input type='hidden' name='mto_month[$i]' value='$mto_month[$i]' /> // <input type='hidden' name='mto_day[$i]' value='$mto_day[$i]' /> // $mto_day[$i]-$mto_month[$i]-$mto_year[$i]"; $from_date[$i] = "{$mfrm_year[$i]}-{$mfrm_month[$i]}-{$mfrm_day[$i]}"; $to_date[$i] = "{$mto_year[$i]}-{$mto_month[$i]}-{$mto_day[$i]}"; $hidden_date = "\r\n\t\t\t\t\t<input type='hidden' name='from_date[{$i}]' value='{$from_date[$i]}' />\r\n\t\t\t\t\t<input type='hidden' name='to_date[{$i}]' value='{$to_date[$i]}' />"; // $from_disp = "$items_data[from_date]"; // $to_disp = "$items_data[to_date]"; } else { if ($items_data["basis"] == "per_week") { $from_disp = "Weeks: {$items_data['weeks']}"; $to_disp = ""; } } } if (!isset($return[$i])) { $return[$i] = ""; } if (!isset($hidden_date)) { $hidden_date = ""; } if (!isset($rain_days[$i])) { $rain_days[$i] = 0; } if ($items_data["basis"] == "per_day") { $rd_disp = "<input type='hidden' name='rain_days[{$i}]' \t\t\t\r\n\t\t\t\t\t\tvalue='{$rain_days[$i]}' size='3' style='text align: center' />"; if ($items_data["half_day"]) { // $hd_disp = "<input type='checkbox' name='half_day[$i]' value='1' checked /> Half Day</b>"; $hd_disp = "<input type='hidden' name='half_day[{$i}]' value='1' />"; } else { $hd_disp = "<input type='hidden' name='half_day[{$i}]' value='0' />"; // $hd_disp = "<input type='checkbox' name='half_day[$i]' value='1' /> Half Day"; } } else { $hd_disp = ""; $rd_disp = "<input type='hidden' name='rain_days[{$i}]' value='0' />"; } if ($items_data["weekends"]) { $weekends[$i] = "checked"; } else { $weekends[$i] = ""; } // Items should not be removed once processed, use reprint to check // if this hire note has already been processed. if (isset($reprint) && $reprint || !empty($monthly)) { $rem_cbox = ""; } else { $rem_cbox = "<td><input type='checkbox' name='remove[{$i}]'></td>"; } if (isset($monthly) && $monthly) { if ($items_data["basis"] == "per_day") { $ret_cbox = "<td><input type='checkbox' name='return[{$i}]' value='checked' {$return[$i]}></td>"; } else { $ret_cbox = "<td> </td>"; } } else { $ret_cbox = "<td><input type='checkbox' name='return[{$i}]' value='checked' {$return[$i]}></td>"; } $amt = sprint($items_data["amt"]); if (user_is_admin(USER_ID)) { $amount_out = "<input type='text' name='amount[{$i}]' value='{$amt}' size='7' />"; } else { $amount_out = "<input type='hidden' name='amount[{$i}]' value='{$amt}' />{$amt}"; } $items_out .= "\r\n\t\t\t<input type='hidden' name='asset_id[{$i}]' value='{$ad['id']}' />\r\n\t\t\t<input type='hidden' name='basis[{$i}]' value='{$items_data['basis']}' />\r\n\t\t\t<input type='hidden' name='qty[{$i}]' value='{$items_data['qty']}' />\r\n\t\t\t{$hidden_date}\r\n\t\t\t{$rd_disp}\r\n\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t<td>{$basis_disp}</td>\r\n\t\t\t\t<td>{$asset_disp}</td>\r\n\t\t\t\t<td align='center'>{$items_data['qty']}</td>\r\n\t\t\t\t<td align='center'>{$from_disp}</td>\r\n\t\t\t\t<td align='center'>{$to_disp} {$hd_disp}</td>\r\n\t<!--\t\t\t\r\n\t\t\t\t<td align='center'>{$rd_disp}</td>\r\n\t\t\t\t<td align='center'>{$items_data['collection']}</td>\r\n\t-->\r\n\t\t\t\t<td>{$amount_out}</td>\r\n\t\t\t\t{$rem_cbox}\r\n\t\t\t\t{$ret_cbox}\r\n\t\t\t</tr>"; } $temp_assets = implode(",", $temp_assets); // New Items -------------------------------------------------------------- // Avoid undefined variable items_out if (empty($items_out)) { $items_out = ""; } // Buttons if (!empty($cusnum)) { if ($deposit_type == "CSH" && $deposit_amt != "0.00") { $deposit_open = "popupOpen(\"hire-invoice-print.php?key=cash_receipt&invid={$inv_data['invid']}\")"; } else { $deposit_open = ""; } $sql = "SELECT * FROM cubit.customers WHERE cusnum='{$cusnum}'"; $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customers."); $cust_data = pg_fetch_array($cust_rslt); $telno = $cust_data["bustel"]; $return_btn = "<input type='submit' name='upBtn' value='Return' />"; if (isset($reprint) && $reprint) { $new_btn = "<input type='button' value='Reprint' onclick='javascript:printer(\"hire/hire_note_reprint.php?invid={$inv_data['invid']}\");{$deposit_open}'>"; $purch_btn = ""; //$purch_btn = "<input type='button' value='Payment' onclick='javascript:popupOpen(\"".SELF."?key=newpos&cusnum=$cusnum\");' />"; } else { if (!$monthly) { $new_btn = "<input name='hirenewBtn' type='submit' value='Process' />"; } else { $new_btn = "<input type='submit' name='upBtn' value='Invoice' />"; } $purch_btn = ""; } $hire_buttons = "\r\n\t\t\t<tr>\r\n\t\t\t\t<td> </td>\r\n\t\t\t\t<td align='center'>\r\n\t\t\t\t\t<input type='submit' name='upBtn' value='Update'>\r\n\t\t\t\t\t{$new_btn}\r\n\t\t\t\t\t{$return_btn}\r\n\t\t\t\t\t{$purch_btn}\r\n\t\t\t\t\t<!--<input type='button' value='Swap Hire' />-->\r\n\t\t\t\t</td>\r\n\t\t\t\t<td> </td>\r\n\t\t\t</tr>"; $basevis = "visible"; $credit_limit = CUR . sprint($cust_data["credlimit"] - $cust_data["balance"]); $cust_balance = CUR . $cust_data["balance"]; } else { $hire_buttons = ""; $basevis = "hidden"; $credit_limit = ""; $cust_balance = ""; } // Retrieve assets $sql = "SELECT * FROM cubit.assets ORDER BY des ASC"; $nasset_rslt = db_exec($sql) or errDie("Unable to retrieve asset."); // Assets dropdown $nasset_sel = "\r\n\t\t<select name='nasset_id' style='visibility: {$basevis}; width: 120px' onchange='assetChange(this);'>\r\n\t\t\t<option value='0'>- SELECT PLANT -</option>"; while ($ad = pg_fetch_array($nasset_rslt)) { $sql = "SELECT * FROM hire.hire_invitems WHERE asset_id='{$ad['id']}' AND invid='{$invid}'"; $invitem_rslt = db_exec($sql) or errDie("Unable to retrieve items."); if (pg_num_rows($invitem_rslt)) { continue; } if (!empty($ad["remaction"])) { continue; } if (isHired($ad["id"], date("Y-m-d"))) { continue; } if (!isSerialized($ad["id"])) { $at = "q"; //$asset_disp = "$ad[des] ($ad[serial2] available.)"; $units_avail = unitsAvailable($ad["id"], date("Y-m-d")); $asset_disp = "{$ad['des']} {$units_avail} available."; if ($ad["serial2"] <= 0) { continue; } } else { $at = "s"; $asset_disp = "{$ad['des']} ({$ad['serial']})"; } if ($cust_bk = isBooked($ad["id"], date("Y-m-d"))) { $sql = "SELECT surname FROM cubit.customers WHERE cusnum='{$cust_bk}'"; $surname_rslt = db_exec($sql) or errDie("Unable to retrieve customer."); $surname = pg_fetch_result($surname_rslt, 0); if (isSerialized($ad["id"])) { $asset_disp .= " Booked: {$surname}"; } else { $units_booked = unitsBooked($ad["id"], date("Y-m-d")); $asset_disp .= " {$units_booked} Units Booked"; } } if ($bk_asset == $ad["id"]) { $sel = "selected='selected'"; } else { $sel = ""; } $nasset_sel .= "<option value='{$at}:{$ad['id']}' {$sel}>{$asset_disp}</option>"; } $nasset_sel .= "</select>"; // Create basis dropdown $nbasis_sel = "\r\n\t\t<select name='nbasis' style='width: 100%; visibility: {$basevis};' onchange='basisChange(this);'>\r\n\t\t\t<option value='0'>- BASIS -</option>"; foreach ($basis_list as $key => $value) { $nbasis_sel .= "<option value='{$key}'>{$value}</option>"; } $nbasis_sel .= "</select>"; // Create asset group dropdown $sql = "SELECT grpid, grpname FROM cubit.assetgrp ORDER BY grpname ASC"; $grp_rslt = db_exec($sql) or errDie("Unable to retrieve groups."); if ($cusnum) { $OTS_OPT = onthespot_encode(SELF, "cust_selection", "deptid={$deptid}&cusnum={$cusnum}&invid={$invid}"); // $cust_edit = " // <td nowrap> // <a href='javascript: popupSized(\"../cust-edit.php?cusnum=$cusnum&onthespot=$OTS_OPT\", \"edit_cust\", 700, 630);'> // Edit Customer Details // </a> // </td>"; $cust_edit = ""; } else { $cust_edit = ""; } // Retrieve service date $sql = "SELECT * FROM hire.hire_invitems WHERE invid='{$invid}'"; $invi_rslt = db_exec($sql) or errDie("Unable to retrieve item."); $sv_warn = ""; while ($invi_data = pg_fetch_array($invi_rslt)) { $sql = "SELECT * FROM cubit.asset_svdates WHERE svdate<=CURRENT_DATE AND asset_id='{$invi_data['asset_id']}'"; $sv_rslt = db_exec($sql) or errDie("Unable to retrieve service date."); $sv_data = pg_fetch_array($sv_rslt); // Retrieve asset if (pg_num_rows($sv_rslt)) { $sql = "SELECT * FROM cubit.assets WHERE id='{$sv_data['asset_id']}'"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset."); $asset_data = pg_fetch_array($asset_rslt); $sv_warn .= "<li class='err'><b>SERVICING</b>: " . getSerial($asset_data["id"], 1) . "\r\n\t\t\t{$asset_data['des']} has a service date on {$sv_data['svdate']}.</li>"; } if ($days = checkServicing($invi_data["asset_id"], 1)) { $sv_warn .= "<li class='err'><b>SERVICING</b>: {$asset_data['des']} needs servicing.</li>"; } } // Check if we should use the default comments if (empty($inv_data["comm"])) { $sql = "SELECT value FROM cubit.settings WHERE constant='HIRE_COMMENTS'"; $comment_rslt = db_exec($sql) or errDie("Unable to retrieve comments."); $inv_data["comm"] = pg_fetch_result($comment_rslt, 0); } // Site address $addr_sel = ""; if ($cusnum) { // Retrieve branch address $sql = "SELECT branch_addr FROM hire.hire_invoices WHERE invid='{$invid}'"; $addr_rslt = db_exec($sql) or errDie("Unable to retrieve branch address."); $branch_addr = pg_fetch_result($addr_rslt, 0); $sql = "SELECT id, branch_name FROM cubit.customer_branches WHERE cusnum='{$cusnum}'"; $bran_rslt = db_exec($sql) or errDie("Unable to retrieve customer branch."); $addr_sel = "<select name='branch_addr' style='width: 100%' onchange='javascript:document.form.submit()'>"; $addr_sel .= "<option value='0'>Physical Address</option>"; while ($bran_data = pg_fetch_array($bran_rslt)) { if ($branch_addr == $bran_data["id"]) { $sel = "selected='selected'"; } else { $sel = ""; } $addr_sel .= "<option value='{$bran_data['id']}' {$sel}>{$bran_data['branch_name']}</option>"; } $addr_sel .= "</select>"; $addr_sel .= "<br />" . branchAddress($branch_addr, $cusnum); } $booked_items = getBookedItems($cusnum, date("Y-m-d")); foreach ($booked_items as $asset_id => $units_booked) { $sql = "SELECT des FROM cubit.assets WHERE id='{$asset_id}'"; $bkdes_rslt = db_exec($sql) or errDie("Unable to retrieve bookings."); $bkdes = pg_fetch_result($bkdes_rslt, 0); $sv_warn .= "<li class='err'><b>BOOKING</b>: {$units_booked}x " . getSerial($asset_id, 1) . " {$bkdes} booked for this customer.</li>"; } if ($monthly) { $ret_out = "Invoice"; } else { $ret_out = "Return"; } // Items should not be removed once processed, use reprint to check // if this hire note has already been processed or if its monthly. if (isset($reprint) && $reprint || !empty($monthly)) { $rem_th = ""; $rem_nbsp = ""; } else { $rem_th = "<th>Remove</th>"; $rem_nbsp = "<td> </td>"; } // Use the customer trad discount on default $sql = "SELECT traddisc FROM cubit.customers WHERE cusnum='{$cusnum}'"; $cust_rslt = db_exec($sql) or errDie("Unable to retrieve discount."); $trade_discount = pg_fetch_result($cust_rslt, 0); // Determine if we got any items, if we do, we don't need to go for the // default value anymore, because the customer is already selected. $sql = "SELECT count(id) FROM hire.hire_invitems WHERE invid='{$invid}'"; $count_rslt = db_exec($sql) or errDie("Unable to retrieve items."); $count = pg_fetch_result($count_rslt, 0); if ($count) { $trade_discount = $inv_data["traddisc"]; } if (isset($bk_id) && $bk_id && !isset($bk_done)) { $sql = "\r\n\t\t\tSELECT serial FROM hire.bookings\r\n\t\t\t\tLEFT JOIN cubit.assets ON bookings.asset_id=assets.id\r\n\t\t\tWHERE bookings.id='{$bk_id}'"; $bk_rslt = db_exec($sql) or errDie("Unable to retrieve booking."); $serialized = pg_fetch_result($bk_rslt, 0); if ($serialized == "Not Serialized") { $qty_disabled = ""; } else { $qty_disabled = "disabled='t'"; } } else { $qty_disabled = "disabled='t'"; } // New Items $new_items_out = "\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td>{$nbasis_sel}</td>\r\n\t\t\t<td>{$nasset_sel}</td>\r\n\t\t\t<td align='center'>\r\n\t\t\t\t<input type='text' id='nqty' name='nqty' value='' size='3' class='clear' {$qty_disabled} style='text-align:center' />\r\n\t\t\t</td>\r\n\t\t\t<td align='left' nowrap='t'>\r\n\t\t\t\t<div id='d_wks' style='height: 0px; visibility: hidden;'>\r\n\t\t\t\t\tWeeks: <input type='text' name='weeks' size='5' style='text-align: center;' />\r\n\t\t\t\t</div>\r\n\t\t\t\t<div id='d_hrs' style='height: 0px; visibility: hidden;'>\r\n\t\t\t\t\tHours: <input type='text' name='hours' size='5'\r\n\t\t\t\t\t\tstyle='text-align: center;' />\r\n\t\t\t\t</div>\r\n\t\t\t\t<div id='d_fdate' style='visibility: hidden;'>\r\n\t\t\t\t\t" . mkDateSelect("nhifrm", $nhifrm_year, $nhifrm_month, $nhifrm_day) . "\r\n\t\t\t\t</div>\r\n\t\t\t</td>\r\n\t\t\t<td align='left' nowrap='t'>\r\n\t\t\t\t<div id='d_tdate' style='visibility: hidden;'>\r\n\t\t\t\t\t" . mkDateSelect("nhito", $nhito_year, $nhito_month, $nhito_day) . "\r\n\t<!--\t\t\t\t\r\n\t\t\t\t\t<input type='checkbox' name='nhalf_day' value='checked' />\r\n\t\t\t\t\tHalf Day\r\n\t-->\t\t\t\r\n\t\t\t\t</div>\r\n\t\t\t</td>\r\n\t\t\t<td> </td>\r\n\t\t\t{$rem_nbsp}\r\n\t\t\t<td> </td>\r\n\t\t</tr>"; /* -- Final Layout -- */ $details = "\r\n\t\t<script>\r\n\t\t\tfunction basisChange(o) {\r\n\t\t\t\thrs = getObject('d_hrs');\r\n\t\t\t\tfd = getObject('d_fdate');\r\n\t\t\t\ttd = getObject('d_tdate');\r\n\t\t\t\twks = getObject('d_wks');\r\n\r\n\t\t\t\tswitch (o.value) {\r\n\t\t\t\t\tcase 'per_hour':\r\n\t\t\t\t\t\thrs.style.visibility = 'visible';\r\n\t\t\t\t\t\tfd.style.visibility = 'hidden';\r\n\t\t\t\t\t\ttd.style.visibility = 'hidden';\r\n\t\t\t\t\t\twks.style.visibility = 'hidden';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'per_day':\r\n\t\t\t\t\t\thrs.style.visibility = 'hidden';\r\n\t\t\t\t\t\tfd.style.visibility = 'visible';\r\n\t\t\t\t\t\ttd.style.visibility = 'visible';\r\n\t\t\t\t\t\twks.style.visibility = 'hidden';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'per_week':\r\n\t\t\t\t\t\thrs.style.visibility = 'hidden';\r\n\t\t\t\t\t\tfd.style.visibility = 'hidden';\r\n\t\t\t\t\t\ttd.style.visibility = 'hidden';\r\n\t\t\t\t\t\twks.style.visibility = 'visible';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\thrs.style.visibility = 'hidden';\r\n\t\t\t\t\t\tfd.style.visibility = 'hidden';\r\n\t\t\t\t\t\ttd.style.visibility = 'hidden';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tfunction assetChange(o) {\r\n\t\t\t\tqo = getObject('nqty');\r\n\r\n\t\t\t\tswitch(o.value.substr(0, 1)) {\r\n\t\t\t\t\tcase 'q':\r\n\t\t\t\t\t\tqo.value = '';\r\n\t\t\t\t\t\tqo.disabled = false;\r\n\t\t\t\t\t\tqo.className = 'std';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 's':\r\n\t\t\t\t\t\tqo.value = '1';\r\n\t\t\t\t\t\tqo.disabled = true;\r\n\t\t\t\t\t\tqo.className = 'clear';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tqo.value = '';\r\n\t\t\t\t\t\tqo.disabled = true;\r\n\t\t\t\t\t\tqo.className = 'clear'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t</script>\r\n\t\t<style>\r\n\t\t\ttd, input, textarea, select { font-size: .75em; }\r\n\t\t</style>\r\n\t\t<center>\r\n\t\t<form method='POST' name='formName'>\r\n\t\t\t<input type='hidden' name='key' value='update'>\r\n\t\t</form>\r\n\t\t<form action='" . SELF . "' method='POST' name='form'>\r\n\t\t\t<input type='hidden' name='collection' value='{$collection}' />\r\n\t\t\t<input type='hidden' name='key' value='update'>\r\n\t\t\t<input type='hidden' name='invid' value='{$invid}' />\r\n\t\t\t<input type='hidden' name='temp_assets' value='{$temp_assets}' />\r\n\t\t\t<input type='hidden' name='monthly' value='{$monthly}' />\r\n\t\t\t<input type='hidden' name='cusnum' value='{$cusnum}' />\r\n\t\t\t<input type='hidden' name='chrgvat' value='no' />\r\n\t\t\t<input type='hidden' name='bk_id' value='{$bk_id}' />\r\n\t\t\t<input type='hidden' name='bk_done' value='1' />\r\n\t\t\t<input type='hidden' name='reprint' value='{$reprint}' />\r\n\t\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t\t \t<tr>\r\n\t\t \t\t<td colspan='3' align='center'><h3>New Hire</h3></td>\r\n\t\t \t</tr>\r\n\t\t \t<tr>\r\n\t\t \t\t<td valign='top'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'> Customer Details </th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Department</td>\r\n\t\t\t\t\t\t\t<td valign='center'>{$dept_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer</td>\r\n\t\t\t\t\t\t\t<td valign='center'>{$cust_sel}</td>\r\n\t\t\t\t\t\t\t{$cust_edit}\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer Telephone Number</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='20' name='telno' value='{$telno}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer Order number</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='10' name='cordno' value='{$cordno}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Available Credit</td>\r\n\t\t\t\t\t\t\t<td>{$credit_limit}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Balance</td>\r\n\t\t\t\t\t\t\t<td>{$cust_balance}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer Address</td>\r\n\t\t\t\t\t\t\t<td>{$addr_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t<!--\r\n\t\t\t\t\t\t<tr><th colspan='2'>Point of Hire</th></tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Barcode</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='text' size='13' name='bar' value=''>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td nowrap='t'>Search for description</td>\r\n\t\t\t\t\t\t\t<td><input type='text' size='13' name='des' value='{$des}'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td colspan='2' align='center'>\r\n\t\t\t\t\t\t\t\t<input type='submit' value='Search'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Collection Method</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='checkbox' name='client_collect' value='checked' {$client_collect} />\r\n\t\t\t\t\t\t\t\tClient Collect\r\n\t\t\t\t\t\t\t\t<br />\r\n\t\t\t\t\t\t\t\t<input type='checkbox' name='deliver' value='checked' {$deliver} />\r\n\t\t\t\t\t\t\t\tTo be Delivered\r\n\t\t\t\t\t\t\t\t<br />\r\n\t\t\t\t\t\t\t\t<input type='checkbox' name='collect' value='checked' {$collect} />\r\n\t\t\t\t\t\t\t\tTo be Collected\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t-->\r\n\t\t\t\t\t</table>\r\n\t\t\t\t<td valign='top' align='center' style='width: 100%;'>\r\n\t\t\t\t\t<img src='../compinfo/getimg.php' style='border: 1px solid #000' width='230' height='47' />\r\n\t\t\t\t</td>\r\n\t\t\t\t</td>\r\n\t\t\t\t<td valign='top' align='right'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan=2>Hire Details</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Hire No.</td>\r\n\t\t\t\t\t\t\t<td valign='center'>H{$inv_data['invnum']}" . rev($inv_data["invid"]) . "</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Sales Order No.</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='5' name='ordno' value='{$inv_data['ordno']}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Hire Date</td>\r\n\t\t\t\t\t\t\t<td valign='center' nowrap='t'>\r\n\t\t\t\t\t\t\t\t" . mkDateSelect("pinv", $pinv_year, $pinv_month, $pinv_day) . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Sales Person</td>\r\n\t\t\t\t\t\t\t<td>{$salesp_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Trade Discount</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='5' name='traddisc'\r\n\t\t\t\t\t\t\t\tvalue='{$trade_discount}'>%\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td nowrap='t'>Delivery Charge</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='7' name='delchrg'\r\n\t\t\t\t\t\t\t\tvalue='{$inv_data['delchrg']}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'>Payment Details </th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>User</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='hidden' name='user' value='" . USER_NAME . "'>\r\n\t\t\t\t\t\t\t\t" . USER_NAME . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Deposit Type</td>\r\n\t\t\t\t\t\t\t<td>{$deposit_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Deposit Amount</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='text' name='deposit_amt'\r\n\t\t\t\t\t\t\t\tvalue='" . sprint($inv_data["deposit_amt"]) . "' size='7' />\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t<tr>\r\n\t\t\t\t<td colspan='3'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'></tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th>Basis</th>\r\n\t\t\t\t\t\t\t<th>Item</th>\r\n\t\t\t\t\t\t\t<th>Qty</th>\r\n\t\t\t\t\t\t\t<th>Hire Date</th>\r\n\t\t\t\t\t\t\t<th>Expected Return</th>\r\n\t\t\t<!--\t\t\t\r\n\t\t\t\t\t\t\t<th>Rain Days</th>\r\n\t\t\t\t\t\t\t<th>Collection</th>\r\n\t\t\t-->\r\n\t\t\t\t\t\t\t<th>Amount</th>\r\n\t\t\t\t\t\t\t{$rem_th}\r\n\t\t\t\t\t\t\t<th>{$ret_out}</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t{$items_out}\r\n\t\t\t\t\t\t{$new_items_out}\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t<tr>\r\n\t\t\t\t<td width='70%' valign='top' colspan='2'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td colspan='10'>{$sv_warn}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td rowspan='4' nowrap>" . mkQuickLinks(ql("javascript:popupOpen(\"../customers-new.php\")", "New Customer"), ql("../pos-invoice-new.php", "New POS Invoice"), ql("../nons-invoice-new.php", "New Non-Stock Invoice")) . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t<th>Comments</th>\r\n\t\t\t\t\t\t\t<th>Custom Text</th>\r\n\t\t\t\t\t\t\t<td rowspan='5' valign='top' width=40%>{$error}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td rowspan=4 align=center valign=top>\r\n\t\t\t\t\t\t\t\t<textarea name=comm cols=20 style='height: 100%'>{$inv_data['comm']}</textarea>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t<td rowspan='4' align='center' valign='top'>\r\n\t\t\t\t\t\t\t\t<textarea name='custom_txt' rows='4' cols='60' style='height: 100%'>{$custom_txt}</textarea>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t\t<td colspan='2' align='right' valign='top' width='30%'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Delivery Charge</td>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['delivery']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Trade Discount</td>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['discount']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>SUBTOTAL</td>\r\n\t\t\t\t\t\t\t<td align=right>\r\n\t\t\t\t\t\t\t\t" . CUR . "<input type=hidden name='subtot' value='{$inv_data['subtot']}'>\r\n\t\t\t\t\t\t\t\t" . sprint($inv_data["subtot"]) . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td><b>VAT {$vat14}</b></td>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['vat']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<th>GRAND TOTAL</th>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['total']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t{$rounding}\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t{$hire_buttons}\r\n\t\t</table>\r\n\t\t<a name='bottom'>\r\n\t\t</form>\r\n\t\t</center>"; return $details; }
function details($_POST, $error = "") { # Get vars extract($_POST); # validate input require_lib("validate"); $v = new validate(); if (isset($invid)) { $v->isOk($invid, "num", 1, 20, "Invalid invoice number."); } if (isset($deptid)) { $v->isOk($deptid, "num", 1, 20, "Invalid department number."); } if (isset($letters)) { $v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters."); } # display errors, if any if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $error .= "<li class='err'>{$e['msg']}</li>"; } $confirm .= "{$error}<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $confirm; } if (!isset($deptid)) { $deptid = 0; } else { if (isset($invid)) { db_conn("cubit"); $sql = "UPDATE rec_invoices SET deptid='{$deptid}' WHERE invid='{$invid}' AND deptid<>'{$deptid}'"; db_exec($sql) or errDie("Error updating invoice department."); } } if (!isset($invid)) { $invid = create_dummy($deptid); $stkerr = "0,0"; } if (!isset($done)) { $done = ""; } if (!isset($stkerr)) { $stkerr = "0,0"; } # Get invoice info db_connect(); $sql = "SELECT * FROM rec_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get invoice information"); if (pg_numrows($invRslt) < 1) { return "<li class='err'>Invoice Not Found</li>"; } $inv = pg_fetch_array($invRslt); # Get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$inv['deptid']}' AND div = '" . USER_DIV . "'"; $deptRslt = db_exec($sql); if (pg_numrows($deptRslt) < 1) { $dept['deptname'] = "<li class='err'>Department not Found.</li>"; } else { $dept = pg_fetch_array($deptRslt); } # Get selected Customer info if (isset($letters)) { db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$inv['cusnum']}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to view customer"); if (pg_numrows($custRslt) < 1) { db_connect(); if ($inv['deptid'] == 0) { $searchdept = ""; } else { $searchdept = "deptid = '{$inv['deptid']}' AND "; } # Query server for customer info $sql = "\n\t\t\t\tSELECT * FROM customers \n\t\t\t\tWHERE {$searchdept} location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND blocked != 'yes' AND div = '" . USER_DIV . "' \n\t\t\t\tORDER BY surname"; $custRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($custRslt) < 1) { $ajax_err = "<li class='err'>No customer names starting with <b>{$letters}</b> in database.</li>"; //return view_err($_POST, $err); } else { $customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>"; $customers .= "<option value='-S' selected>Select Customer</option>"; while ($cust = pg_fetch_array($custRslt)) { $customers .= "<option value='{$cust['cusnum']}'>{$cust['cusname']} {$cust['surname']}</option>"; } $customers .= "</select>"; } # Take care of the unset vars $cust['addr1'] = ""; $cust['cusnum'] = ""; $cust['vatnum'] = ""; $cust['accno'] = ""; } else { $cust = pg_fetch_array($custRslt); $sql = "SELECT * FROM customers WHERE deptid = '{$inv['deptid']}' AND location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND blocked != 'yes' AND div = '" . USER_DIV . "' ORDER BY surname"; $cusRslt = db_exec($sql) or errDie("Unable to view customers"); # Moarn if customer account has been blocked if ($cust['blocked'] == 'yes') { $error .= "<li class='err'>Error : Selected customer account has been blocked.</li>"; } // $customers = "<input type=hidden name=cusnum value='$cust[cusnum]'>$cust[cusname] $cust[surname]"; $cusnum = $cust['cusnum']; $customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>"; // $customers .= "<option value='-S' selected>Select Customer</option>"; while ($cus = pg_fetch_array($cusRslt)) { $sel = ""; if ($cust['cusnum'] == $cus['cusnum']) { $sel = "selected"; } $customers .= "<option value='{$cus['cusnum']}' {$sel}>{$cus['cusname']} {$cus['surname']}</option>"; } $customers .= "</select>"; } } /* --- Start Drop Downs --- */ # Select warehouse db_conn("exten"); // $whs = "<select name='whidss[]' onChange='javascript:document.form.submit();'>"; $whs = "<select name='whidss[]'>"; $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "' ORDER BY whname ASC"; $whRslt = db_exec($sql); if (pg_numrows($whRslt) < 1) { return "<li class='err'> There are no Stores found in Cubit.</li>"; } else { $whs .= "<option value='-S' disabled selected>Select Store</option>"; while ($wh = pg_fetch_array($whRslt)) { if (!user_in_store_team($wh["whid"], USER_ID)) { continue; } $whs .= "<option value='{$wh['whid']}'>({$wh['whno']}) {$wh['whname']}</option>"; } } $whs .= "</select>"; # Get sales people db_conn("exten"); $sql = "SELECT * FROM salespeople WHERE div = '" . USER_DIV . "' ORDER BY salesp ASC"; $salespRslt = db_exec($sql) or errDie("Unable to get sales people."); if (pg_numrows($salespRslt) < 1) { return "<li class='err'> There are no Sales People found in Cubit.</li>"; } else { $salesps = "<select name='salespn'>"; while ($salesp = pg_fetch_array($salespRslt)) { if ($salesp['salesp'] == $inv['salespn']) { $sel = "selected"; } else { $sel = ""; } $salesps .= "<option value='{$salesp['salesp']}' {$sel}>{$salesp['salesp']}</option>"; } $salesps .= "</select>"; } # Days drop downs $days = array("0" => "0", "7" => "7", "14" => "14", "30" => "30", "60" => "60", "90" => "90", "120" => "120"); $termssel = extlib_cpsel("terms", $days, $inv['terms']); # Keep the charge vat option stable if ($inv['chrgvat'] == "inc") { $chin = "checked=yes"; $chex = ""; $chno = ""; } elseif ($inv['chrgvat'] == "exc") { $chin = ""; $chex = "checked=yes"; $chno = ""; } else { $chin = ""; $chex = ""; $chno = "checked=yes"; } # Format date list($rinv_year, $rinv_month, $rinv_day) = explode("-", $inv['odate']); /* --- End Drop Downs --- */ // get the ID of the first warehouse db_conn("exten"); $sql = "SELECT whid FROM warehouses ORDER BY whid ASC LIMIT 1"; $rslt = db_exec($sql) or errDie("Error reading warehouses (FWH)."); if (pg_num_rows($rslt) > 0) { $FIRST_WH = pg_fetch_result($rslt, 0, 0); } else { $FIRST_WH = "-S"; } /* --- Start Products Display --- */ # Select all products $products = "\n\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t<tr>\n\t\t\t\t<th>STORE</th>\n\t\t\t\t<th>ITEM NUMBER</th>\n\t\t\t\t<th>VAT CODE</th>\n\t\t\t\t<th>DESCRIPTION</th>\n\t\t\t\t<th>QTY</th>\n\t\t\t\t<th>UNIT PRICE</th>\n\t\t\t\t<th>UNIT DISCOUNT</th>\n\t\t\t\t<th>AMOUNT</th>\n\t\t\t\t<th>Remove</th>\n\t\t\t<tr>"; # get selected stock in this invoice db_connect(); $sql = "SELECT * FROM recinv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $i = 0; $key = 0; while ($stkd = pg_fetch_array($stkdRslt)) { $stkd['account'] += 0; if ($stkd['account'] != 0) { # Keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t<select name='accounts[]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } if ($ad['accid'] == $stkd['account']) { $sel = "selected"; } else { $sel = ""; } $Accounts .= "<option value='{$ad['accid']}' {$sel}>{$ad['accname']}</option>"; } $Accounts .= "</select>"; $sernos = ""; # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[]' value='{$stkd['qty']}'>"; $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$stkd['unitcost']}'>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stkd['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in product $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whids[]' value='{$stkd['whid']}'></td>\n\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stkd['stkid']}'>{$Vatcodes}</td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptions[]' value='{$stkd['description']}'> {$sernos}</td>\n\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t<td><input type='hidden' name='disc[]' value='{$stkd['disc']}'><input type='hidden' name='discp[]' value='{$stkd['discp']}'></td>\n\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$stkd['amt']}'> " . CUR . " " . sprint($stkd['amt']) . "</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$key}'><input type='hidden' name='SCROLL' value='yes'></td>\n\t\t\t\t</tr>"; $key++; } else { # Keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; # Get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stkd['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # Get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sernos = "<input type='hidden' name='sernos[]' value='{$stkd['serno']}'>{$stkd['serno']}"; # check permissions if (perm("invoice-unitcost-edit.php")) { $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$stkd['unitcost']}'>"; } else { $viewcost = "<input type='hidden' size='8' name='unitcost[]' value='{$stkd['unitcost']}'>{$stkd['unitcost']}"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stkd['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in product $products .= "\n\t\t\t\t<input type='hidden' name='accounts[]' value='0'>\n\t\t\t\t<input type='hidden' name='descriptions[]' value=''>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' name='whids[]' value='{$stkd['whid']}'>{$wh['whname']}</td>\n\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stkd['stkid']}'><a href='#bottom' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t{$sernos}\n\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtys[]' value='{$stkd['qty']}'></td>\n\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t<td><input type='text' size='4' name='disc[]' value='{$stkd['disc']}'> OR <input type='text' size='4' name='discp[]' value='{$stkd['discp']}' maxlength='5'>%</td>\n\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$stkd['amt']}'> " . CUR . " " . sprint($stkd['amt']) . "</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$key}'><input type='hidden' name='SCROLL' value='yes'></td>\n\t\t\t\t</tr>"; $key++; } } # Look above(remprod keys) $keyy = $key; # Look above(if i = 0 then there are no products) if ($i == 0) { $done = ""; } else { $SCROLL = "yes"; } # check if stock warehouse was selected if (isset($whidss)) { foreach ($whidss as $key => $whid) { if (isset($stkidss[$key]) && $stkidss[$key] != "-S" && isset($cust['pricelist'])) { # skip if not selected if ($whid == "-S") { continue; } # Get selected warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$whid}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # Get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkidss[$key]}' AND div = '" . USER_DIV . "' ORDER BY stkcod ASC"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sernos = "<input type='hidden' name='sernos[]' value=''>"; # Get price from price list if it is set if (isset($cust['pricelist'])) { # get selected stock in this warehouse db_conn("exten"); $sql = "SELECT price FROM plist_prices WHERE listid = '{$cust['pricelist']}' AND stkid = '{$stk['stkid']}' AND div = '" . USER_DIV . "'"; $plRslt = db_exec($sql); if (pg_numrows($plRslt) > 0) { $pl = pg_fetch_array($plRslt); $stk['selamt'] = $pl['price']; } } /* -- Start Some Checks -- */ # check if they are selling too much if ($stk['units'] - $stk['alloc'] < $qtyss[$key]) { if (!in_array($stk['stkid'], explode(",", $stkerr))) { if ($stk['type'] != 'lab') { $stkerr .= ",{$stk['stkid']}"; $error .= "<li class='err'>Warning : Item number <b>{$stk['stkcod']}</b> does not have enough items available.</li>"; } } } /* -- End Some Checks -- */ # Calculate the Discount discount if ($discs[$key] < 1) { if ($discps[$key] > 0) { $discs[$key] = round($discps[$key] / 100 * $stk['selamt'], 2); } } else { $discps[$key] = round($discs[$key] * 100 / $stk['selamt'], 2); } # Calculate amount $amt[$key] = $qtyss[$key] * ($stk['selamt'] - $discs[$key]); $stk['selamt'] = sprint($stk['selamt']); # Check permissions if (perm("invoice-unitcost-edit.php")) { $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$stk['selamt']}'>"; } else { $viewcost = "<input type='hidden' size='8' name='unitcost[]' value='{$stk['selamt']}'>{$stk['selamt']}"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stk['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $amt[$key] = sprint($amt[$key]); # Put in selected warehouse and stock $products .= "\n\t\t\t\t\t<input type='hidden' name='accounts[]' value='0'>\n\t\t\t\t\t<input type='hidden' name='descriptions[]' value=''>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><input type='hidden' name='whids[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stk['stkid']}'><a href='#bottom' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t\t{$sernos}\n\t\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t\t<td><input type='text' size='3' name='qtys[]' value='{$qtyss[$key]}'></td>\n\t\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t\t<td><input type='text' size='4' name='disc[]' value='{$discs[$key]}'> OR <input type='text' size='4' name='discp[]' value='{$discps[$key]}' maxlength='5'>%</td>\n\t\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; } elseif (isset($accountss[$key]) && $accountss[$key] != "0" && isset($cust['pricelist'])) { db_conn('core'); $Sl = "SELECT * FROM accounts WHERE accid='{$accountss[$key]}'"; $Ri = db_exec($Sl) or errDie("Unable to get account data."); if (pg_num_rows($Ri) < 1) { return "invalid."; } $ad = pg_fetch_array($Ri); # Calculate amount $amt[$key] = sprint($qtyss[$key] * $unitcosts[$key]); # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[]' value='{$qtyss[$key]}'>"; # Check permissions $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$unitcosts[$key]}'>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vatcodess[$key] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in selected warehouse and stock $products .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td colspan='2'>{$ad['accname']}<input type='hidden' name='accounts[]' value='{$accountss[$key]}'><input type='hidden' name='whids[]' value='0'></td>\n\t\t\t\t\t\t<td>{$Vatcodes}<input type='hidden' name='stkids[]' value='0'></td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='descriptions[]' value='{$descriptionss[$key]}'></td>\n\t\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t\t<td><input type='hidden' name='disc[]' value='0'><input type='hidden' name='discp[]' value='0'></td>\n\t\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; } else { if (!isset($diffwhBtn)) { # skip if not selected if ($whid == "-S") { continue; } if (!isset($addnon)) { # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$whid}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); if (isset($ria) && $ria != "") { $len = strlen($ria); if ($ria == "Show All") { $Wh = ""; $ria = ""; } else { $Wh = "AND (lower(stkdes) LIKE lower('%{$ria}%')) OR (lower(stkcod) LIKE lower('%{$ria}%'))"; // $Wh = "AND lower(substr(stkcod,1,'$len'))=lower('$ria')"; } } else { $Wh = "AND FALSE"; $ria = ""; } # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE whid = '{$whid}' AND blocked = 'n' AND div = '" . USER_DIV . "' AND serd = 'no' {$Wh} ORDER BY stkcod ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { $error .= "<li class='err'>There are no stock items in the selected warehouse.</li>"; continue; } if (pg_numrows($stkRslt) == 1) { $ex = "selected"; } else { $ex = ""; } if (!isset($sel_frm) || $sel_frm == "stkcod") { $cods = "<select class='width : 15'name='stkidss[]' onChange='javascript:document.form.submit();'>"; $cods .= "<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $cods .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $cods .= "</select> "; $descs = ""; } else { $descs = "<select class='width : 15'name='stkidss[]' onChange='javascript:document.form.submit();'>"; $descs .= "<option value='-S' disabled selected>Select Description</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $descs .= "<option value='{$stk['stkid']}'>{$stk['stkdes']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $descs .= "</select> "; $cods = ""; } # put in drop down and warehouse $products .= "\n\t\t\t\t\t\t\t<input type='hidden' name='accountss[]' value='0'>\n\t\t\t\t\t\t\t<input type='hidden' name='descriptionss[]' value=''>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><input type='hidden' name='whidss[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t\t\t<td>{$cods}</td>\n\t\t\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t\t\t<td>{$descs}</td>\n\t\t\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t\t\t<td><input type='text' size='4' name='discs[]' value='0'> OR <input type='text' size='4' name='discps[]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t\t\t\t<td><input type='hidden' name='amts[]' value='0.00'>" . CUR . " 0.00</td>\n\t\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t</tr>"; } else { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t\t\t\t<select name='accountss[]' onChange='javascript:document.form.submit();'>\n\t\t\t\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value={$ad['accid']}>{$ad['accname']}</option>"; } $Accounts .= "</select>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t\t\t<select name='vatcodess[]'>\n\t\t\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; //<input type='hidden' name='stkidss[]' value=''> $products .= "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whidss[]' value='{$FIRST_WH}'></td>\n\t\t\t\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[]'></td>\n\t\t\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t\t\t\t<td><input type='text' name='unitcosts[]' size='7'></td>\n\t\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t\t\t\t<td><input type='hidden' name='discs[]' value='0'><input type='hidden' name='discps[]' value='0' ></td>\n\t\t\t\t\t\t\t</tr>"; } } } } } else { if (!(isset($diffwhBtn) || isset($addnon))) { # check if setting exists db_connect(); $sql = "SELECT value FROM set WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'"; $Rslt = db_exec($sql) or errDie("Unable to check database for existing settings."); if (pg_numrows($Rslt) > 0) { $set = pg_fetch_array($Rslt); $whid = $set['value']; if (isset($wtd) && $wtd != 0) { $whid = $wtd; } # get selected warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$whid}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); if (isset($ria) && $ria != "") { $len = strlen($ria); if ($ria == "Show All") { $Wh = ""; $ria = ""; } else { $Wh = "AND lower(substr(stkcod,1,'{$len}'))=lower('{$ria}')"; $ria = ""; } } else { $Wh = ""; $ria = ""; } # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE whid = '{$whid}' AND blocked = 'n' AND div = '" . USER_DIV . "' AND serd = 'no' {$Wh} ORDER BY stkcod ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { if (!isset($err)) { $err = ""; } $err .= "<li>There are no stock items in the selected store.</li>"; //ontinue; } $stks = "<select name='stkidss[]' onChange='javascript:document.form.submit();'>"; $stks .= "<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $stks .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $stks .= "</select> "; $products .= "\n\t\t\t\t\t<input type='hidden' name='descriptionss[]' value=''>\n\t\t\t\t\t<input type='hidden' name='vatcodess[]' value=''>\n\t\t\t\t\t<input type='hidden' name='accountss[]' value='0'>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><input type='hidden' name='whidss[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t<td>{$stks}</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td><input type='hidden' size='3' name='qtyss[]' value='1'>1</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td><input type='text' size='4' name='discs[]' value='0'> OR <input type='text' size='4' name='discps[]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t</tr>"; } else { $products .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>{$whs}</td>\n\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t<td><input type='text' size='4' name='discs[]' value='0'> OR <input type='text' size='4' name='discps[]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t</tr>"; } } else { if (isset($addnon)) { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t<select name='accountss[]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>"; } $Accounts .= "</select>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodess[]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whidss[]' value='{$FIRST_WH}'></td>\n\t\t\t\t\t<input type='hidden' name='stkidss[]' value='-S'>\n\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[]'></td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t<td><input type='text' name='unitcosts[]' size='7'></td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t<td><input type='hidden' name='discs[]' value='0'><input type='hidden' name='discps[]' value='0'></td>\n\t\t\t\t</tr>"; } } } /* -- start Listeners -- */ if (isset($diffwhBtn)) { $products .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$whs}</td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td></td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td><input type='text' size='4' name='discs[]' value='0'> OR <input type='text' size='4' name='discps[]' value='0' maxlength='5'>%</td>\n\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t<td></td>\n\t\t\t</tr>"; } /* -- End Listeners -- */ $products .= "</table>"; /* --- End Products Display --- */ /* --- Start Some calculations --- */ # Calculate subtotal $SUBTOT = sprint($inv['subtot']); # Calculate tradediscm if ($inv['traddisc'] > 0) { $traddiscm = sprint($inv['traddisc'] / 100 * ($SUBTOT + $inv['delchrg'])); } else { $traddiscm = "0.00"; } $VATP = TAX_VAT; # Calculate subtotal $SUBTOT = sprint($inv['subtot']); $VAT = sprint($inv['vat']); $TOTAL = sprint($inv['total']); $inv['delchrg'] = sprint($inv['delchrg']); /* --- End Some calculations --- */ /*--- Start checks --- */ # check only if the customer is selected if (isset($cusnum) && $cusnum != "-S") { #check againg credit limit if ($TOTAL + $cust['balance'] > $cust['credlimit']) { $error .= "<li class='err'>Warning : Customers Credit limit of <b>" . CUR . " " . sprint($cust["credlimit"]) . "</b> has been exceeded"; } $avcred = $cust['credlimit'] - $cust['balance']; } else { $avcred = "0.00"; } $inv['delvat'] += 0; if ($inv['delvat'] == 0) { $Sl = "SELECT * FROM vatcodes WHERE del='Yes'"; $Ri = db_exec($Sl) or errDie("Unable to get data."); $vd = pg_fetch_array($Ri); $inv['delvat'] = $vd['id']; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t<select name='delvat'>\n\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['id'] == $inv['delvat']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; db_conn('cubit'); $Sl = "SELECT * FROM costcenters"; $Ri = db_exec($Sl); if (pg_num_rows($Ri) > 0) { $ctd = "\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Cost Center</th>\n\t\t\t\t\t<th>Percentage</th>\n\t\t\t\t</tr>"; $i = 0; while ($data = pg_fetch_array($Ri)) { $Sl = "SELECT * FROM invc WHERE inv='{$invid}' AND cid='{$data['ccid']}'"; $Rq = db_exec($Sl); $cd = pg_fetch_array($Rq); $ctd .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$data['centername']}</td>\n\t\t\t\t\t<td><input type='text' name='ct[{$data['ccid']}]' size='5' value='{$cd['amount']}'>%</td>\n\t\t\t\t</tr>"; $i++; } $ctd .= "</table>"; } else { $ctd = ""; } // Retrieve default comments from Cubit if (empty($inv["comm"])) { db_conn("cubit"); $sql = "SELECT value FROM settings WHERE constant='DEFAULT_COMMENTS'"; $commRslt = db_exec($sql) or errDie("Unable to retrieve default comment from Cubit."); $comment = base64_decode(pg_fetch_result($commRslt, 0)); } else { $comment = $inv["comm"]; } if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } // Which display method was selected if (isset($sel_frm) && $sel_frm == "stkdes") { $sel_frm_cod = ""; $sel_frm_des = "checked"; } else { $sel_frm_cod = "checked"; $sel_frm_des = ""; } /*--- Start checks --- */ /* -- Final Layout -- */ $details_begin = "\n\t\t<center>\n\t\t<h3>Recurring Invoice</h3>\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t<input type='hidden' name='key' value='update'>\n\t\t\t<input type='hidden' name='invid' value='{$invid}'>\n\t\t\t<input type='hidden' name='stkerr' value='{$stkerr}'>\n\t\t<table " . TMPL_tblDflts . " width='95%'>\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<div id='cust_selection'>"; if (empty($ajax_err) && (isset($cusnum) || AJAX)) { if (isset($cusnum)) { $OTS_OPT = onthespot_encode(SELF, "cust_selection", "deptid={$inv['deptid']}&letters={$letters}&cusnum={$cusnum}&invid={$invid}"); $custedit = "\n\t\t\t\t<td nowrap>\n\t\t\t\t\t<a href='javascript: popupSized(\"cust-edit.php?cusnum={$cusnum}&onthespot={$OTS_OPT}\", \"edit_cust\", 700, 630);'>\n\t\t\t\t\t\tEdit Customer Details\n\t\t\t\t\t</a>\n\t\t\t\t</td>"; } else { $custedit = ""; } $ajaxOut = "\n\t\t\t<input type='hidden' name='letters' value='{$letters}'>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'> Customer Details </th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Department</td>\n\t\t\t\t\t<td valign='center'>{$dept['deptname']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account No.</td>\n\t\t\t\t\t<td valign='center'>{$cust['accno']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer</td>\n\t\t\t\t\t<td valign='center'>{$customers}</td>\n\t\t\t\t\t{$custedit}\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Customer Address</td>\n\t\t\t\t\t<td valign='center'>" . nl2br($cust['addr1']) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer Order number</td>\n\t\t\t\t\t<td valign='center'><input type='text' size='10' name='cordno' value='{$inv['cordno']}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer VAT Number</td>\n\t\t\t\t\t<td>{$cust['vatnum']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Point of Sale</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Barcode</td>\n\t\t\t\t\t<td><input type='text' size='13' name='bar' value=''></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Using</td>\n\t\t\t\t\t<td>Stock Code<input type='radio' name='sel_frm' value='stkcod' onChange='javascript:document.form.submit();' {$sel_frm_cod}><br>Stock Description<input type='radio' name='sel_frm' value='stkdes' onChange='javascript:document.form.submit();' {$sel_frm_des}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "' " . ass("Type the first letters of the stock code you are looking for.") . ">\n\t\t\t\t\t<td>Stock Filter</td>\n\t\t\t\t\t<td nowrap><input type='text' size='13' name='ria' value='{$ria}'> <input type='submit' value='Search'> <input type='submit' name='ria' value='Show All'></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; } else { # Query server for depts db_conn("exten"); $sql = "SELECT * FROM departments WHERE div = '" . USER_DIV . "' ORDER BY deptname ASC"; $deptRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($deptRslt) < 1) { return "<li class='err'>There are no Departments found in Cubit.</li>"; } else { $depts = "<select id='deptid'>"; $depts .= "<option value='0'>All Departments</option>"; while ($dept = pg_fetch_array($deptRslt)) { $depts .= "<option value='{$dept['deptid']}'>{$dept['deptname']}</option>"; } $depts .= "</select>"; } if (!isset($ajax_err)) { $ajax_err = ""; } $ajaxOut = "\n\t\t\t<script>\n\t\t\t\tfunction updateCustSelection() {\n\t\t\t\t\tdeptid = getObject('deptid').value;\n\t\t\t\t\tletters = getObject('letters').value;\n\t\t\t\t\tajaxRequest('" . SELF . "', 'cust_selection', AJAX_SET, 'letters='+letters+'&deptid='+deptid+'&invid={$invid}');\n\t\t\t\t}\n\t\t\t</script>\n\t\t\t{$ajax_err}\n\t\t\t<table " . TMPL_tblDflts . " width='400'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>New Recurring Invoice</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Department</td>\n\t\t\t\t\t<td valign='center'>{$depts}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>First Letters of customer</td>\n\t\t\t\t\t<td valign='center'><input type='text' size='5' id='letters' maxlength='5'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td> </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td valign='center'><input type='button' value='Update' onClick='updateCustSelection();'></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; } if (isset($diffwhBtn) or isset($addprodBtn) or isset($addnon) or isset($upBtn) or isset($saveBtn) or isset($ria)) { $jump_bot = "\n\t\t\t<script>\n\t\t\t\twindow.location.hash='bottom';\n\t\t\t</script>"; } else { $jump_bot = ""; } $details_end = "\n\t\t\t\t\t</div>\n\t\t\t\t</td>\n\t\t\t\t<td valign='top' align='right'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'> Invoice Details </th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Invoice No.</td>\n\t\t\t\t\t\t\t<td valign='center'>RI {$inv['invid']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Document Ref No.</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='docref' value='{$inv['docref']}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Sales Order No.</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='ordno' value='{$inv['ordno']}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>VAT Inclusive</td>\n\t\t\t\t\t\t\t<td valign='center'>Yes <input type='radio' size='7' name='chrgvat' value='inc' {$chin}> No<input type='radio' size='7' name='chrgvat' value='exc' {$chex}></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Terms</td>\n\t\t\t\t\t\t\t<td valign='center'>{$termssel} Days</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Sales Person</td>\n\t\t\t\t\t\t\t<td valign='center'>{$salesps}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Invoice Date</td>\n\t\t\t\t\t\t\t<td valign='center'>" . mkDateSelect("rinv", $rinv_year, $rinv_month, $rinv_day) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Available Credit</td>\n\t\t\t\t\t\t\t<td>" . CUR . " " . sprint($avcred) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Trade Discount</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='traddisc' value='{$inv['traddisc']}'>%</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Delivery Charge</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='7' name='delchrg' value='{$inv['delchrg']}'>{$Vatcodes}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td colspan='2'>{$ctd}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'>{$products}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t\t<p>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td rowspan='2'>" . mkQuickLinks(ql("cust-credit-stockinv.php", "New Invoice"), ql("rec-invoice-view.php", "View Recurring Invoices"), ql("customers-new.php", "New Customer")) . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<th width='25%'>Comments</th>\n\t\t\t\t\t\t\t<td rowspan='5' valign='top' width='50%'>{$error}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td class='" . bg_class() . "' rowspan='4' align='center' valign='top'><textarea name='comm' rows='4' cols='20'>{$comment}</textarea></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td align='right' valign='top'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>SUBTOTAL</td>\n\t\t\t\t\t\t\t<td align='right'>" . CUR . " <input type='hidden' name='SUBTOT' value='{$SUBTOT}'>{$SUBTOT}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Trade Discount</td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$inv['discount']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Delivery Charge</td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$inv['delivery']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><b>VAT {$vat14}</b></td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$VAT}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<th>GRAND TOTAL</th>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$TOTAL}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td align='right'><input name='diffwhBtn' type='submit' value='Different Store'> | <input name='addprodBtn' type='submit' value='Add Product'> | <input name='addnon' type='submit' value='Add Non stock Product'> | <input type='submit' name='upBtn' value='Update'> </td>\n\t\t\t\t<td> | <input type='submit' name='saveBtn' value='Save »'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<a name='bottom'>\n\t\t</form>\n\t\t</center>\n\t\t{$jump_bot}"; if (AJAX) { return $ajaxOut; } else { return "{$details_begin}{$ajaxOut}{$details_end}"; } }
function details($_POST, $error = "") { extract($_POST); # validate input include "libs/validate.lib.php"; $v = new validate(); if (isset($quoid)) { $v->isOk($quoid, "num", 1, 20, "Invalid quote number."); } if (isset($deptid)) { $v->isOk($deptid, "num", 1, 20, "Invalid department number."); } if (isset($letters)) { $v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters."); } # display errors, if any if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $error .= "<li class='err'>{$e['msg']}</li>"; } $confirm .= "{$error}<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $confirm; } if (!isset($deptid)) { $deptid = 0; } else { if (isset($quoid)) { db_conn("cubit"); $sql = "UPDATE quotes SET deptid='{$deptid}' WHERE quoid='{$quoid}' AND deptid<>'{$deptid}'"; db_exec($sql) or errDie("Error updating invoice department."); } } if (!isset($quoid)) { $quoid = create_dummy($deptid); } if (!isset($stkerr)) { $stkerr = "0,0"; } if (!isset($done)) { $done = ""; } if (!isset($sel_frm)) { $sel_frm = "stkcod"; } # Get quote info db_connect(); $sql = "SELECT * FROM quotes WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $quoRslt = db_exec($sql) or errDie("Unable to get quote information"); if (pg_numrows($quoRslt) < 1) { return "<li class='err'>Quote Not Found</li>"; } $quo = pg_fetch_array($quoRslt); # check if quote has been printed if ($quo['accepted'] == "y") { $error = "<li class='err'> Error : Quote number <b>{$quoid}</b> has already been printed.</li>"; $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $error; } if (!isset($lead)) { $lead = $quo["lead"]; } //manual error handling if (!isset($quo['ncdate'])) { $quo['ncdate'] = ""; } if (strlen($quo['ncdate']) < 1) { $ncdate_year = date("Y"); $ncdate_month = date("m", mktime(0, 0, 0, date("m"), date("d") + 5, date("Y"))); $ncdate_day = date("d", mktime(0, 0, 0, date("m"), date("d") + 5, date("Y"))); } else { $darr = explode("-", $quo['ncdate']); $ncdate_year = $darr['0']; $ncdate_month = $darr['1']; $ncdate_day = $darr['2']; } # get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$quo['deptid']}' AND div = '" . USER_DIV . "'"; $deptRslt = db_exec($sql); if (pg_numrows($deptRslt) < 1) { $dept['deptname'] = "<li class='err'>Department not Found.</li>"; } else { $dept = pg_fetch_array($deptRslt); } # Get selected customer info if (isset($letters)) { db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$quo['cusnum']}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to view customer"); if (pg_numrows($custRslt) < 1) { db_connect(); if ($inv['deptid'] == 0) { $searchdept = ""; } else { $searchdept = "deptid = '{$quo['deptid']}' AND "; } # Query server for customer info $sql = "SELECT cusnum,cusname,surname FROM customers WHERE {$searchdept} location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND div = '" . USER_DIV . "' ORDER BY surname"; $custRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($custRslt) < 1) { $ajax_err = "<li class='err'>No customer names starting with <b>{$letters}</b> in database.</li>"; //return view_err($_POST, $err); } else { $customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>"; $customers .= "<option value='-S' selected>Select Customer</option>"; while ($cust = pg_fetch_array($custRslt)) { $customers .= "<option value='{$cust['cusnum']}'>{$cust['cusname']} {$cust['surname']}</option>"; } $customers .= "</select>"; } # take care of the unset vars $cust['addr1'] = ""; $cust['cusnum'] = ""; $cust['vatnum'] = ""; $cust['accno'] = ""; } else { $cust = pg_fetch_array($custRslt); # moarn if customer account has been blocked if ($cust['blocked'] == 'yes') { return "<li class='err'>Error : Selected customer account has been blocked.</li>"; } $customers = "<input type='hidden' name=cusnum value='{$cust['cusnum']}'>{$cust['cusname']} {$cust['surname']}"; $cusnum = $cust['cusnum']; } } /* --- Start Drop Downs --- */ # Select warehouse db_conn("exten"); //no good ... breaks the search feature because it doesnt send search with // onChange='javascript:document.form.submit();' $whs = "<select name='whidss[]'>"; $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "' ORDER BY whname ASC"; $whRslt = db_exec($sql); if (pg_numrows($whRslt) < 1) { return "<li class='err'> There are no Stores found in Cubit.</li>"; } else { $whs .= "<option value='-S' disabled selected>Select Store</option>"; while ($wh = pg_fetch_array($whRslt)) { if (!user_in_store_team($wh["whid"], USER_ID)) { continue; } $whs .= "<option value='{$wh['whid']}'>({$wh['whno']}) {$wh['whname']}</option>"; } } $whs .= "</select>"; # get sales people db_conn("exten"); $sql = "SELECT * FROM salespeople WHERE div = '" . USER_DIV . "' ORDER BY salesp ASC"; $salespRslt = db_exec($sql) or errDie("Unable to get sales people."); if (pg_numrows($salespRslt) < 1) { return "<li class='err'> There are no Sales People found in Cubit.</li>"; } else { $salesps = "<select name='salespn'>"; while ($salesp = pg_fetch_array($salespRslt)) { if ($salesp['salesp'] == $quo['salespn']) { $sel = "selected"; } else { $sel = ""; } $salesps .= "<option value='{$salesp['salesp']}' {$sel}>{$salesp['salesp']}</option>"; } $salesps .= "</select>"; } # days drop downs $days = array("0" => "0", "7" => "7", "14" => "14", "30" => "30", "60" => "60", "90" => "90", "120" => "120"); $termssel = extlib_cpsel("terms", $days, $quo['terms']); # Keep the charge vat option stable if ($quo['chrgvat'] == "inc") { $chin = "checked=yes"; $chex = ""; $chno = ""; } elseif ($quo['chrgvat'] == "exc") { $chin = ""; $chex = "checked=yes"; $chno = ""; } else { $chin = ""; $chex = ""; $chno = "checked=yes"; } # format date list($quote_year, $quote_month, $quote_day) = explode("-", $quo['odate']); // list($followon_year, $followon_month, $followon_day) = explode("-", $quo['ncdate']); /* --- End Drop Downs --- */ // get the ID of the first warehouse db_conn("exten"); $sql = "SELECT whid FROM warehouses ORDER BY whid ASC LIMIT 1"; $rslt = db_exec($sql) or errDie("Error reading warehouses (FWH)."); if (pg_num_rows($rslt) > 0) { $FIRST_WH = pg_fetch_result($rslt, 0, 0); } else { $FIRST_WH = "-S"; } /* --- Start Products Display --- */ # select all products $products = "\n\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t<tr>\n\t\t\t\t<th>STORE</th>\n\t\t\t\t<th>ITEM NUMBER</th>\n\t\t\t\t<th>VAT CODE</th>\n\t\t\t\t<th>DESCRIPTION</th>\n\t\t\t\t<th>QTY</th>\n\t\t\t\t<th>UNIT PRICE</th>\n\t\t\t\t<th>UNIT DISCOUNT</th>\n\t\t\t\t<th>AMOUNT</th>\n\t\t\t\t<th>Remove</th>\n\t\t\t<tr>"; # get selected stock in this quote db_connect(); $sql = "SELECT * FROM quote_items WHERE quoid = '{$quoid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $i = 0; $key = 0; while ($stkd = pg_fetch_array($stkdRslt)) { $stkd['account'] += 0; if ($stkd['account'] != 0) { # Keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t<select name='accounts[]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } if ($ad['accid'] == $stkd['account']) { $sel = "selected"; } else { $sel = ""; } $Accounts .= "<option value='{$ad['accid']}' {$sel}>{$ad['accname']}</option>"; } $Accounts .= "</select>"; $sernos = ""; $stkd['unitcost'] = sprint($stkd['unitcost']); $stkd['amt'] = sprint($stkd['amt']); # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[]' value='{$stkd['qty']}'>"; $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$stkd['unitcost']}'>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stkd['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; //print "fo"; # Put in product $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whids[]' value='{$stkd['whid']}'></td>\n\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stkd['stkid']}'>{$Vatcodes}</td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptions[]' value='{$stkd['description']}'> {$sernos}</td>\n\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t<td><input type='hidden' name='disc[]' value='{$stkd['disc']}'><input type='hidden' name='discp[]' value='{$stkd['discp']}'></td>\n\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$stkd['amt']}'> " . CUR . " {$stkd['amt']}</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$key}'><input type='hidden' name='SCROLL' value='yes'></td>\n\t\t\t\t</tr>"; $key++; } else { # keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; # get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stk['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stkd['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $stkd['unitcost'] = sprint($stkd['unitcost']); $stkd['amt'] = sprint($stkd['amt']); # put in product $products .= "\n\t\t\t\t<input type='hidden' name='accounts[]' value='0'>\n\t\t\t\t<input type='hidden' name='descriptions[]' value=''>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' name='whids[]' value='{$stkd['whid']}'>{$wh['whname']}</td>\n\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stkd['stkid']}'><a href='#' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtys[]' value='{$stkd['qty']}'></td>\n\t\t\t\t\t<td><input type='text' size='8' name='unitcost[]' value='{$stkd['unitcost']}'></td>\n\t\t\t\t\t<td><input type='text' size='4' name='disc[]' value='{$stkd['disc']}'> OR <input type='text' size='4' name='discp[]' value='{$stkd['discp']}' maxlength=5>%</td>\n\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$stkd['amt']}'> " . CUR . " {$stkd['amt']}</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$key}'><input type='hidden' name='SCROLL' value='yes'></td>\n\t\t\t\t</tr>"; $key++; } } # Look above(remprod keys) $keyy = $key; # look above(if i = 0 then there are no products) if ($i == 0) { $done = ""; } # check if stock warehouse was selected if (isset($whidss)) { foreach ($whidss as $key => $whid) { if (isset($stkidss[$key]) && $stkidss[$key] != "-S" && isset($cust['pricelist'])) { # skip if not selected if ($whid == "-S") { continue; } # get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkidss[$key]}' AND div = '" . USER_DIV . "' ORDER BY stkcod ASC"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); # get selected warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stk['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get price from price list if it is set if (isset($cust['pricelist'])) { # get selected stock in this warehouse db_conn("exten"); $sql = "SELECT price FROM plist_prices WHERE listid = '{$cust['pricelist']}' AND stkid = '{$stk['stkid']}' AND div = '" . USER_DIV . "'"; $plRslt = db_exec($sql); if (pg_numrows($plRslt) > 0) { $pl = pg_fetch_array($plRslt); $stk['selamt'] = $pl['price']; } } /* -- Start Some Checks -- */ # check if they are selling too much if ($stk['units'] - $stk['alloc'] < $qtyss[$key]) { if (!in_array($stk['stkid'], explode(",", $stkerr))) { if ($stk['type'] != 'lab') { $stkerr .= ",{$stk['stkid']}"; $error .= "<li class='err'>Warning : Item number <b>{$stk['stkcod']}</b> does not have enough items available.</li>"; } } } /* -- End Some Checks -- */ # Calculate the Discount discount if ($discs[$key] < 1) { if ($discps[$key] > 0) { $discs[$key] = round($discps[$key] / 100 * $stk['selamt'], 2); } } else { $discps[$key] = round($discs[$key] * 100 / $stk['selamt'], 2); } # Calculate amount $amt[$key] = $qtyss[$key] * ($stk['selamt'] - $discs[$key]); db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stk['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $stk['selamt'] = sprint($stk['selamt']); $amt[$key] = sprint($amt[$key]); # put in selected warehouse and stock $products .= "\n\t\t\t\t\t<input type='hidden' name='accounts[]' value='0'>\n\t\t\t\t\t<input type='hidden' name='descriptions[]' value=''>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><input type='hidden' name='whids[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stk['stkid']}'><a href='#' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t\t<td><input type='text' size='3' name='qtys[]' value='{$qtyss[$key]}'></td>\n\t\t\t\t\t\t<td><input type='text' size='8' name='unitcost[]' value='{$stk['selamt']}'></td>\n\t\t\t\t\t\t<td><input type='text' size='4' name='disc[]' value='{$discs[$key]}'> OR <input type='text' size='4' name='discp[]' value='{$discps[$key]}' maxlength='5'>%</td>\n\t\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; } elseif (isset($accountss[$key]) && $accountss[$key] != "0" && isset($cust['pricelist'])) { db_conn('core'); $Sl = "SELECT * FROM accounts WHERE accid='{$accountss[$key]}'"; $Ri = db_exec($Sl) or errDie("Unable to get account data."); if (pg_num_rows($Ri) < 1) { return "invalid."; } $ad = pg_fetch_array($Ri); # Calculate amount $amt[$key] = sprint($qtyss[$key] * $unitcosts[$key]); # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[]' value='{$qtyss[$key]}'>"; $unitcosts[$key] = sprint($unitcosts[$key]); $amt[$key] = sprint($amt[$key]); # Check permissions $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$unitcosts[$key]}'>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t<select name='vatcodes[]'>\n\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vatcodess[$key] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in selected warehouse and stock $products .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td colspan='2'>{$ad['accname']}<input type='hidden' name='accounts[]' value='{$accountss[$key]}'><input type='hidden' name='whids[]' value='0'></td>\n\t\t\t\t\t\t<td>{$Vatcodes}<input type='hidden' name='stkids[]' value='0'></td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='descriptions[]' value='{$descriptionss[$key]}'></td>\n\t\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t\t<td><input type='hidden' name='disc[]' value='0'><input type='hidden' name='discp[]' value='0'></td>\n\t\t\t\t\t\t<td nowrap><input type='hidden' name='amt[]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; } else { # skip if not selected if ($whid == "-S") { continue; } if (!isset($addnon)) { if (isset($filter_store) and $filter_store != "0") { # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$filter_store}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); } if (isset($des) and $des != "") { $len = strlen($des); if ($des == "Show All") { $Wh = ""; $des = ""; } else { $Wh = "AND (lower(substr(stkdes,1,'{$len}'))=lower('{$des}') OR lower(substr(stkcod,1,'{$len}'))=lower('{$des}'))"; } } else { $Wh = "AND FALSE"; $des = ""; } $check_setting = getCSetting("OPTIONAL_STOCK_FILTERS"); if (isset($check_setting) and $check_setting == "yes") { if (isset($filter_class) and $filter_class != "0") { $Wh .= " AND prdcls = '{$filter_class}'"; } if (isset($filter_cat) and $filter_cat != "0") { $Wh .= " AND catid = '{$filter_cat}'"; } } if (isset($filter_store) and $filter_store != "0") { $Wh .= " AND whid = '{$filter_store}'"; } # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE blocked = 'n' AND div = '" . USER_DIV . "' {$Wh} ORDER BY stkcod ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { $error .= "<li class='err'>There are no stock items in the selected store.</li>"; continue; } if ($sel_frm == "stkcod") { $cods = "<select name='stkidss[]' onChange='javascript:document.form.submit();'>"; $cods .= "<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $cods .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $cods .= "</select> "; $descs = ""; } else { $descs = "<select style='width:250px' name='stkidss[]' onChange='javascript:document.form.submit();'>"; $descs .= "<option value='-S' disabled selected>Select Description</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $descs .= "<option value='{$stk['stkid']}'>{$stk['stkdes']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $descs .= "</select> "; $cods = ""; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t\t<select name='vatcodess[]'>\n\t\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # put in drop down and warehouse $products .= "\n\t\t\t\t\t\t<input type='hidden' name='accountss[]' value='0'>\n\t\t\t\t\t\t<input type='hidden' name='descriptionss[]' value=''>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><input type='hidden' name='whidss[]' value='{$filter_store}'></td>\n\t\t\t\t\t\t\t<td>{$cods}<input type='hidden' name='vatcodess' value='0'></td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td>{$descs}</td>\n\t\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t\t<td><input type='text' size='4' name='discs[]' value='0'> OR <input type='text' size='4' name='discps[]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t\t\t<td><input type='hidden' name='amts[]' value='0.00'>" . CUR . " 0.00</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t</tr>"; } else { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t\t\t<select name='accountss[]'>\n\t\t\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>"; } $Accounts .= "</select>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t\t<select name='vatcodess[]'>\n\t\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $products .= "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whidss[]' value='{$FIRST_WH}'></td>\n\t\t\t\t\t\t\t<inpu type='hidden' name='stkidss[]' value=''>\n\t\t\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[]'></td>\n\t\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t\t\t<td><input type='text' name='unitcosts[]' size='7'></td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t\t\t<td><input type='hidden' name='discs[]' value='0'><input type='hidden' name='discps[]' value='0' ></td>\n\t\t\t\t\t\t</tr>"; } } } } else { if (!isset($addnon) && !isset($upBtn)) { if (isset($filter_store) and $filter_store != "0") { # get selected warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$filter_store}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); } if (isset($des) and $des != "") { $len = strlen($des); if ($des == "Show All") { $Wh = ""; $des = ""; } else { $Wh = "AND (lower(substr(stkdes,1,'{$len}'))=lower('{$des}') OR lower(substr(stkcod,1,'{$len}'))=lower('{$des}'))"; } } else { $Wh = "AND FALSE"; $des = ""; } $check_setting = getCSetting("OPTIONAL_STOCK_FILTERS"); if (isset($check_setting) and $check_setting == "yes") { if (isset($filter_class) and $filter_class != "0") { $Wh .= " AND prdcls = '{$filter_class}'"; } if (isset($filter_cat) and $filter_cat != "0") { $Wh .= " AND catid = '{$filter_cat}'"; } } if (isset($filter_store) and $filter_store != "0") { $Wh .= " AND whid = '{$filter_store}'"; } # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE blocked = 'n' AND div = '" . USER_DIV . "' {$Wh} ORDER BY stkcod ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { if (!isset($err)) { $err = ""; } $err .= "<li>There are no stock items in the selected warehouse.</li>"; } $stks = "<select name='stkidss[]' onChange='javascript:document.form.submit();'>"; $stks .= "<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $stks .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $stks .= "</select> "; $products .= "\n\t\t\t\t<input type='hidden' name='descriptionss[]' value=''>\n\t\t\t\t<input type='hidden' name='vatcodess[]' value=''>\n\t\t\t\t<input type='hidden' name='accountss[]' value='0'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' name='whidss[]' value='{$filter_store}'></td>\n\t\t\t\t\t<td>{$stks}</td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td><input type='text' size='4' name='discs[]' value='0'> OR <input type='text' size='4' name='discps[]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t<td></td>\n\t\t\t\t</tr>"; } else { if (isset($addnon)) { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t<select name='accountss[]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>"; } $Accounts .= "</select>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodess[]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whidss[]' value='{$FIRST_WH}'></td>\n\t\t\t\t\t<inpu type='hidden' name='stkidss[]' value=''>\n\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[]'></td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t<td><input type='text' name='unitcosts[]' size='7'></td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t<td><input type='hidden' name='discs[]' value='0'><input type='hidden' name='discps[]' value='0'></td>\n\t\t\t\t</tr>"; } } } $products .= "</table>"; /* --- End Products Display --- */ /* --- Start Some calculations --- */ # Calculate subtotal $SUBTOT = sprint($quo['subtot']); $VATP = TAX_VAT; # Calculate subtotal $SUBTOT = sprint($quo['subtot']); $VAT = sprint($quo['vat']); $TOTAL = sprint($quo['total']); /* --- End Some calculations --- */ /*--- Start checks --- */ # check only if the customer is selected if (isset($cusnum) && $cusnum != "-S") { #check againg credit limit if ($cust['credlimit'] != 0 && $TOTAL + $cust['balance'] > $cust['credlimit']) { $error .= "<li class='err'>Warning : Customers Credit limit of <b>" . CUR . " {$cust['credlimit']}</b> has been exceeded</li>"; } $avcred = $cust['credlimit'] - $cust['balance']; } else { $avcred = "0.00"; } $quo['delvat'] += 0; if ($quo['delvat'] == 0) { $Sl = "SELECT * FROM vatcodes WHERE del='Yes'"; $Ri = db_exec($Sl) or errDie("Unable to get data."); $vd = pg_fetch_array($Ri); $quo['delvat'] = $vd['id']; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t<select name='delvat'>\n\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['id'] == $quo['delvat']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } // Which display method was selected if (isset($sel_frm) && $sel_frm == "stkdes") { $sel_frm_cod = ""; $sel_frm_des = "checked"; } else { $sel_frm_cod = "checked"; $sel_frm_des = ""; } $sel = ""; if (isset($lead) and strlen($lead) > 0) { $sel = "checked=yes"; } /*--- Start checks --- */ /* -- Final Layout --No VAT<input type=radio size=7 name=chrgvat value='nov' $chno> */ $details_begin = "\n\t\t<center>\n\t\t<h3>New Quote</h3>\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t<input type='hidden' name='key' value='update'>\n\t\t\t<input type='hidden' name='quoid' value='{$quoid}'>\n\t\t<table " . TMPL_tblDflts . " width='95%'>\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<div id='cust_selection'>"; if (empty($ajax_err) && (isset($cusnum) || AJAX)) { if (isset($cusnum)) { $OTS_OPT = onthespot_encode(SELF, "cust_selection", "deptid={$quo['deptid']}&letters={$letters}&cusnum={$cusnum}&quoid={$quoid}"); $custedit = "\n\t\t\t\t<td nowrap>\n\t\t\t\t\t<a href='javascript: popupSized(\"cust-edit.php?cusnum={$cusnum}&onthespot={$OTS_OPT}\", \"edit_cust\", 700, 630);'>Edit Customer Details</a>\n\t\t\t\t</td>"; } else { $custedit = ""; } $optional_filter_setting = getCSetting("OPTIONAL_STOCK_FILTERS"); if (isset($optional_filter_setting) and $optional_filter_setting == "yes") { db_connect(); $catsql = "SELECT catid, cat, catcod FROM stockcat WHERE div = '" . USER_DIV . "' ORDER BY cat ASC"; $catRslt = db_exec($catsql); if (pg_numrows($catRslt) < 1) { $cat_drop = "<input type='hidden' name='filter_cat' value='0'>"; } else { $cat_drop = "<select name='filter_cat'>"; $cat_drop .= "<option value='0'>All Categories</option>"; while ($cat = pg_fetch_array($catRslt)) { if (isset($filter_cat) and $filter_cat == $cat['catid']) { $cat_drop .= "<option value='{$cat['catid']}' selected>({$cat['catcod']}) {$cat['cat']}</option>"; } else { $cat_drop .= "<option value='{$cat['catid']}'>({$cat['catcod']}) {$cat['cat']}</option>"; } } $cat_drop .= "</select>"; } # Select classification $classsql = "SELECT * FROM stockclass WHERE div = '" . USER_DIV . "' ORDER BY classname ASC"; $clasRslt = db_exec($classsql); if (pg_numrows($clasRslt) < 1) { $class_drop = "<input type='hidden' name='filter_class' value='0'>"; } else { $class_drop = "<select name='filter_class' style='width: 167'>"; $class_drop .= "<option value='0'>All Classifications</option>"; while ($clas = pg_fetch_array($clasRslt)) { if (isset($filter_class) and $filter_class == $clas['clasid']) { $class_drop .= "<option value='{$clas['clasid']}' selected>{$clas['classname']}</option>"; } else { $class_drop .= "<option value='{$clas['clasid']}'>{$clas['classname']}</option>"; } } $class_drop .= "</select>"; } $display_optional_filters = "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Category</td>\n\t\t\t\t\t<td>{$cat_drop}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Classification</td>\n\t\t\t\t\t<td>{$class_drop}</td>\n\t\t\t\t</tr>"; } db_conn("exten"); $sql = "SELECT whid, whname, whno FROM warehouses WHERE div = '" . USER_DIV . "' ORDER BY whname ASC"; $whRslt = db_exec($sql); if (pg_numrows($whRslt) < 1) { $store_drop = "<input type='hidden' name='filter_store' value='0'>"; } else { if (!isset($filter_store)) { # check if setting exists db_connect(); $sql = "SELECT value FROM set WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'"; $Rslt = db_exec($sql) or errDie("Unable to check database for existing settings."); if (pg_numrows($Rslt) > 0) { $set = pg_fetch_array($Rslt); $filter_store = $set['value']; } } $store_drop = "<select name='filter_store'>"; $store_drop .= "<option value='0'>All Stores</option>"; while ($wh = pg_fetch_array($whRslt)) { if (isset($filter_store) and $filter_store == $wh['whid']) { $store_drop .= "<option value='{$wh['whid']}' selected>({$wh['whno']}) {$wh['whname']}</option>"; } else { $store_drop .= "<option value='{$wh['whid']}'>({$wh['whno']}) {$wh['whname']}</option>"; } } $store_drop .= "</select>"; } $ajaxOut = "\n\t\t\t<input type='hidden' name='letters' value='{$letters}'>\n\t\t\t<input type='hidden' name='stkerr' value='{$stkerr}'>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'> Customer Details </th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Department</td>\n\t\t\t\t\t<td valign='center'>{$dept['deptname']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account No.</td>\n\t\t\t\t\t<td valign='center'>{$cust['accno']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer</td>\n\t\t\t\t\t<td valign='center'>{$customers}</td>\n\t\t\t\t\t{$custedit}\n\t\t\t\t\t<td><input type='button' onClick=\"javascript:document.location=('pos-quote-new.php')\" value='Quote Non Customer'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Customer Address</td>\n\t\t\t\t\t<td valign='center'>" . nl2br($cust['addr1']) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer Req number</td>\n\t\t\t\t\t<td valign='center'><input type='text' size='10' name='cordno' value='{$quo['cordno']}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer VAT Number</td>\n\t\t\t\t\t<td>{$cust['vatnum']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Next Contact Date</td>\n\t\t\t\t\t<td valign='center'>" . mkDateSelect("ncdate", $ncdate_year, $ncdate_month, $ncdate_day) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Add As Lead</td>\n\t\t\t\t\t<td valign='center'><input type='checkbox' name='lead' {$sel} value='yes'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Using</td>\n\t\t\t\t\t<td>Stock Code<input type='radio' name='sel_frm' value='stkcod' onChange='javascript:document.form.submit();' {$sel_frm_cod}><br>Stock Description<input type='radio' name='sel_frm' value='stkdes' onChange='javascript:document.form.submit();' {$sel_frm_des}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Additional Filters</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Store</td>\n\t\t\t\t\t<td>{$store_drop}</td>\n\t\t\t\t</tr>\n\t\t\t\t{$display_optional_filters}\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Stock Filter</td>\n\t\t\t\t\t<td><input type='text' size='13' name='des' value='{$des}'> <input type='submit' value='Search'> <input type='submit' name='des' value='Show All'></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; } else { db_conn("exten"); $sql = "SELECT * FROM departments WHERE div = '" . USER_DIV . "' ORDER BY deptname ASC"; $deptRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($deptRslt) < 1) { return "<li class='err'>There are no Departments found in Cubit.</li>"; } else { $depts = "<select id='deptid'>"; $depts .= "<option value='0'>All Departments</option>"; while ($dept = pg_fetch_array($deptRslt)) { $depts .= "<option value='{$dept['deptid']}'>{$dept['deptname']}</option>"; } $depts .= "</select>"; } if (!isset($ajax_err)) { $ajax_err = ""; } $ajaxOut = "\n\t\t\t<script>\n\t\t\t\tfunction updateCustSelection() {\n\t\t\t\t\tdeptid = getObject('deptid').value;\n\t\t\t\t\tletters = getObject('letters').value;\n\t\t\t\t\tajaxRequest('" . SELF . "', 'cust_selection', AJAX_SET, 'letters='+letters+'&deptid='+deptid+'&quoid={$quoid}');\n\t\t\t\t}\n\t\t\t</script>\n\t\t\t{$ajax_err}\n\t\t\t<table " . TMPL_tblDflts . " width='400'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>New Quote</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>" . REQ . "Select Department</td>\n\t\t\t\t<td valign='center'>{$depts}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>First Letters of customer</td>\n\t\t\t\t<td valign='center'><input type='text' size='5' id='letters' maxlength='5'></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td> </td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td> </td>\n\t\t\t\t<td valign='center'><input type='button' value='Update »' onClick='updateCustSelection();'></td>\n\t\t\t</tr>\n\t\t</table>"; } $avcred = sprint($avcred); if (isset($addprodBtn) or isset($addnon) or isset($saveBtn) or isset($upBtn) or isset($doneBtn) or isset($donePrnt) or isset($des)) { $jump_bot = "\n\t\t\t<script>\n\t\t\t\twindow.location.hash='bottom';\n\t\t\t</script>"; } else { $jump_bot = ""; } $details_end = "\n\t\t\t\t\t</div>\n\t\t\t\t</td>\n\t\t\t\t<td valign='top' align='right'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'> Quote Details </th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Quote No.</td>\n\t\t\t\t\t\t\t<td valign='center'>{$quo['quoid']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Order No.</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='ordno' value='{$quo['ordno']}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>VAT Inclusive</td>\n\t\t\t\t\t\t\t<td valign='center'>Yes <input type='radio' size='7' name='chrgvat' value='inc' {$chin}> No<input type='radio' size='7' name='chrgvat' value='exc' {$chex}> </td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Terms</td>\n\t\t\t\t\t\t\t<td valign='center'>{$termssel} Days</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Sales Person</td>\n\t\t\t\t\t\t\t<td valign='center'>{$salesps}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Quote Date</td>\n\t\t\t\t\t\t\t<td valign='center'>" . mkDateSelect("quote", $quote_year, $quote_month, $quote_day) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Available Credit</td>\n\t\t\t\t\t\t\t<td>" . CUR . " {$avcred}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Trade Discount</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='traddisc' value='{$quo['traddisc']}'>%</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Delivery Charge</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='text' size='7' name='delchrg' value='{$quo['delchrg']}'>{$Vatcodes}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'>{$products}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td rowspan='2'>" . mkQuickLinks(ql("quote-view.php", "View Quotes"), ql("customers-new.php", "New Customer")) . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<th width='25%'>Comments</th>\n\t\t\t\t\t\t\t<td rowspan='5' valign='top' width='50%'>{$error}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td class='" . bg_class() . "' rowspan='4' align='center' valign='top'>\n\t\t\t\t\t\t\t\t<textarea name='comm' rows='4' cols='20'>{$quo['comm']}</textarea>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td align='right'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='80%'>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>SUBTOTAL</td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " <input type='hidden' name='SUBTOT' value='{$SUBTOT}'>{$SUBTOT}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Trade Discount</td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$quo['discount']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Delivery Charge</td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$quo['delivery']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><b>VAT {$vat14}</b></td>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$VAT}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<th>GRAND TOTAL</th>\n\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$TOTAL}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td align='center' colspan='2' nowrap><input name='addprodBtn' type='submit' value='Add Product'> | <input name='addnon' type='submit' value='Add Non stock Product'> | <input type='submit' name='saveBtn' value='Save'> | <input type='submit' name='upBtn' value='Update'>{$done}</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<a name='bottom'>\n\t\t</form>\n\t\t</center>\n\t\t{$jump_bot}"; if (AJAX) { return $ajaxOut; } else { return "{$details_begin}{$ajaxOut}{$details_end}"; } }
function details($_POST, $error = "") { extract($_POST); # validate input include "libs/validate.lib.php"; $v = new validate(); if (isset($calloutid)) { $v->isOk($calloutid, "num", 1, 20, "Invalid callout document number."); } if (isset($deptid)) { $v->isOk($deptid, "num", 1, 20, "Invalid department number."); } if (isset($letters)) { $v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters."); } # display errors, if any if ($v->isError()) { $errors = $v->getErrors(); foreach ($errors as $e) { $error .= "<li class='err'>{$e['msg']}</li>"; } $confirm .= "{$error}<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $confirm; } if (!isset($deptid)) { $deptid = 0; } else { if (isset($calloutid)) { db_conn("cubit"); $sql = "UPDATE callout_docs SET deptid='{$deptid}' WHERE calloutid='{$calloutid}' AND deptid<>'{$deptid}'"; db_exec($sql) or errDie("Error updating invoice department."); } } if (!isset($calloutid)) { db_conn("exten"); #only create dummy if needed resources are available ... $get_cpeople = "SELECT * FROM calloutpeople"; $run_cpeople = db_exec($get_cpeople) or errDie("Unable to get call out person information"); if (pg_numrows($run_cpeople) < 1) { return "\n\t\t\t\t<li class='err'>No Call out People Found. Please add at least one.</li>\n\t\t\t\t<br>\n\t\t\t\t<table border=0 cellpadding='2' cellspacing='1' width=15%>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><a href='toms/calloutp-add.php'>Add Call Out Person</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><a href='main.php'>Main Menu</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>"; } db_connect(); $calloutid = create_dummy($deptid); } if (!isset($stkerr)) { $stkerr = "0,0"; } if (!isset($done)) { $done = ""; } # Get callout document info db_connect(); $sql = "SELECT * FROM callout_docs WHERE calloutid = '{$calloutid}' AND div = '" . USER_DIV . "'"; $docRslt = db_exec($sql) or errDie("Unable to get callout document information"); if (pg_numrows($docRslt) < 1) { return "<li class='err'>Callout Document Not Found</li>"; } $doc = pg_fetch_array($docRslt); # check if callout document has been printed if ($doc['accepted'] == "y") { $error = "<li class='err'> Error : Callout Document number <b>{$calloutid}</b> has already been printed.</li>"; $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $error; } # get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$doc['deptid']}' AND div = '" . USER_DIV . "'"; $deptRslt = db_exec($sql); if (pg_numrows($deptRslt) < 1) { $dept['deptname'] = "<li class='err'>Department not Found.</li>"; } else { $dept = pg_fetch_array($deptRslt); } # Get selected customer info if (isset($letters)) { db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$doc['cusnum']}' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to view customer"); if (pg_numrows($custRslt) < 1) { db_connect(); if ($inv['deptid'] == 0) { $searchdept = ""; } else { $searchdept = "deptid = '{$doc['deptid']}' AND "; } # Query server for customer info $sql = "SELECT cusnum,cusname,surname FROM customers WHERE {$searchdept} location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND div = '" . USER_DIV . "' ORDER BY surname"; $custRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($custRslt) < 1) { $ajax_err = "<li class='err'>No customer names starting with <b>{$letters}</b> in database.</li>"; //return view_err($_POST, $err); } else { $customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>"; $customers .= "<option value='-S' selected>Select Customer</option>"; while ($cust = pg_fetch_array($custRslt)) { $customers .= "<option value='{$cust['cusnum']}'>{$cust['cusname']} {$cust['surname']}</option>"; } $customers .= "</select>"; } # take care of the unset vars $cust['addr1'] = ""; $cust['cusnum'] = ""; $cust['accno'] = ""; } else { $cust = pg_fetch_array($custRslt); # moarn if customer account has been blocked if ($cust['blocked'] == 'yes') { return "<li class='err'>Error : Selected customer account has been blocked.</li>"; } $customers = "<input type='hidden' name='cusnum' value='{$cust['cusnum']}'>{$cust['cusname']} {$cust['surname']}"; $cusnum = $cust['cusnum']; } } /* --- Start Drop Downs --- */ # Select warehouse db_conn("exten"); $whs = "<select name='whidss[]' onChange='javascript:document.form.submit();'>"; $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "' ORDER BY whname ASC"; $whRslt = db_exec($sql); if (pg_numrows($whRslt) < 1) { return "<li class='err'> There are no Stores found in Cubit.</li>"; } else { $whs .= "<option value='-S' disabled selected>Select Store</option>"; while ($wh = pg_fetch_array($whRslt)) { $whs .= "<option value='{$wh['whid']}'>({$wh['whno']}) {$wh['whname']}</option>"; } } $whs .= "</select>"; # get callout people db_conn("exten"); $sql = "SELECT * FROM calloutpeople WHERE div = '" . USER_DIV . "' ORDER BY calloutp ASC"; $run_sql = db_exec($sql) or errDie("Unable to get call out people from system."); if (pg_numrows($run_sql) < 1) { return "<li class='err'> There were no Call Out People found.</li>"; } else { $calloutps = "<select name='calloutp'>"; while ($arr = pg_fetch_array($run_sql)) { if ($doc['calloutp'] == $arr['calloutp']) { $calloutps .= "<option value='{$arr['calloutp']}' selected>{$arr['calloutp']}</option>"; } else { $calloutps .= "<option value='{$arr['calloutp']}'>{$arr['calloutp']}</option>"; } } $calloutps .= "</select>"; } # days drop downs $days = array("0" => "0", "7" => "7", "14" => "14", "30" => "30", "60" => "60", "90" => "90", "120" => "120"); # format date list($call_year, $call_month, $call_day) = explode("-", $doc['odate']); /* --- End Drop Downs --- */ // get the ID of the first warehouse db_conn("exten"); $sql = "SELECT whid FROM warehouses ORDER BY whid ASC LIMIT 1"; $rslt = db_exec($sql) or errDie("Error reading warehouses (FWH)."); if (pg_num_rows($rslt) > 0) { $FIRST_WH = pg_fetch_result($rslt, 0, 0); } else { $FIRST_WH = "-S"; } /* --- Start Products Display --- */ # select all products $products = "\n\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t<tr>\n\t\t\t\t<th>STORE</th>\n\t\t\t\t<th>ITEM NUMBER</th>\n\t\t\t\t<th>DESCRIPTION</th>\n\t\t\t\t<th>QTY</th>\n\t\t\t\t<th>ITEM PRICE</th>\n\t\t\t\t<th>Remove</th>\n\t\t\t<tr>"; # get selected stock in this callout document db_connect(); $sql = "SELECT * FROM cubit.callout_docs_items WHERE calloutid = '{$calloutid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $i = 0; $key = 0; while ($stkd = pg_fetch_array($stkdRslt)) { $stkd['account'] += 0; $stkd['unitcost'] = sprint($stkd['unitcost']); if ($stkd['account'] != 0) { # Keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t<select name='accounts[]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } if ($ad['accid'] == $stkd['account']) { $sel = "selected"; } else { $sel = ""; } $Accounts .= "<option value='{$ad['accid']}' {$sel}>{$ad['accname']}</option>"; } $Accounts .= "</select>"; $sernos = ""; # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[]' value='{$stkd['qty']}'>"; $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$stkd['unitcost']}'>"; # Put in product $products .= "\n\t\t\t\t<input type='hidden' name='whids[]' value='{$stkd['whid']}'>\n\t\t\t\t<input type='hidden' name='stkids[]' value='{$stkd['stkid']}'>\n\t\t\t\t<input type='hidden' name='SCROLL' value='yes'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}</td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptions[]' value='{$stkd['description']}'> {$sernos}</td>\n\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$key}'></td>\n\t\t\t\t</tr>"; $key++; } else { # keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stkd['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); # put in product $products .= "\n\t\t\t\t<input type='hidden' name='accounts[]' value='0'>\n\t\t\t\t<input type='hidden' name='descriptions[]' value=''>\n\t\t\t\t<input type='hidden' name='stkids[]' value='{$stkd['stkid']}'>\n\t\t\t\t<input type='hidden' name='whids[]' value='{$stkd['whid']}'>\n\t\t\t\t<input type='hidden' name='SCROLL' value='yes'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$wh['whname']}</td>\n\t\t\t\t\t<td><a href='#' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtys[]' value='{$stkd['qty']}'></td>\n\t\t\t\t\t<td><input type='text' size='8' name='unitcost[]' value='{$stkd['unitcost']}'></td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$key}'></td>\n\t\t\t\t</tr>"; $key++; } } # Look above(remprod keys) $keyy = $key; # look above(if i = 0 then there are no products) if ($i == 0) { $done = ""; } # check if stock warehouse was selected if (isset($whidss)) { foreach ($whidss as $key => $whid) { if (isset($stkidss[$key]) && $stkidss[$key] != "-S" && isset($cust['pricelist'])) { # skip if not selected if ($whid == "-S") { continue; } # get selected warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$whid}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkidss[$key]}' AND div = '" . USER_DIV . "' ORDER BY stkcod ASC"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); # get price from price list if it is set if (isset($cust['pricelist'])) { # get selected stock in this warehouse db_conn("exten"); $sql = "SELECT price FROM plist_prices WHERE listid = '{$cust['pricelist']}' AND stkid = '{$stk['stkid']}' AND div = '" . USER_DIV . "'"; $plRslt = db_exec($sql); if (pg_numrows($plRslt) > 0) { $pl = pg_fetch_array($plRslt); $stk['selamt'] = $pl['price']; } } /* -- Start Some Checks -- */ # check if they are selling too much if ($stk['units'] - $stk['alloc'] < $qtyss[$key]) { if (!in_array($stk['stkid'], explode(",", $stkerr))) { if ($stk['type'] != 'lab') { $stkerr .= ",{$stk['stkid']}"; $error .= "<li class=err>Warning : Item number <b>{$stk['stkcod']}</b> does not have enough items available.</li>"; } } } /* -- End Some Checks -- */ # Calculate amount $amt[$key] = $qtyss[$key] * $stk['selamt']; $stk['selamt'] = sprint($stk['selamt']); # put in selected warehouse and stock $products .= "\n\t\t\t\t\t<input type='hidden' name='accounts[]' value='0'>\n\t\t\t\t\t<input type='hidden' name='descriptions[]' value=''>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><input type='hidden' name='whids[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stk['stkid']}'><a href='#' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t\t<td><input type='text' size='3' name='qtys[]' value='{$qtyss[$key]}'></td>\n\t\t\t\t\t\t<td><input type='text' size='8' name='unitcost[]' value='{$stk['selamt']}'></td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; } elseif (isset($accountss[$key]) && $accountss[$key] != "0" && isset($cust['pricelist'])) { db_conn('core'); $Sl = "SELECT * FROM accounts WHERE accid='{$accountss[$key]}'"; $Ri = db_exec($Sl) or errDie("Unable to get account data."); if (pg_num_rows($Ri) < 1) { return "invalid."; } $ad = pg_fetch_array($Ri); # Calculate amount $amt[$key] = sprint($qtyss[$key] * $unitcosts[$key]); # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[]' value='{$qtyss[$key]}'>"; # Check permissions $viewcost = "<input type='text' size='8' name='unitcost[]' value='{$unitcosts[$key]}'>"; # Put in selected warehouse and stock $products .= "\n\t \t\t\t\t<input type='hidden' name='accounts[]' value='{$accountss[$key]}'>\n\t \t\t\t\t<input type='hidden' name='whids[]' value='0'>\n\t \t\t\t\t<input type='hidden' name='stkids[]' value='0'>\n\t \t\t\t\t<input type='hidden' name='disc[]' value='0'>\n\t \t\t\t\t<input type='hidden' name='discp[]' value='0'>\n\t \t\t\t\t<tr class='" . bg_class() . "'>\n\t \t\t\t\t\t<td colspan='2'>{$ad['accname']}</td>\n\t \t\t\t\t\t<td><input type='text' size='20' name='descriptions[]' value='{$descriptionss[$key]}'></td>\n\t \t\t\t\t\t<td>{$qtyin}</td>\n\t \t\t\t\t\t<td>{$viewcost}</td>\n\t \t\t\t\t\t<td><input type='hidden' name='amt[]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t \t\t\t\t\t<td><input type='checkbox' name='remprod[]' value='{$keyy}'></td>\n\t \t\t\t\t</tr>"; $keyy++; } else { if (!isset($diffwhBtn)) { # skip if not selected if ($whid == "-S") { continue; } if (!isset($addnon)) { # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$whid}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE whid = '{$whid}' AND blocked = 'n' AND div = '" . USER_DIV . "' ORDER BY stkcod ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { $error .= "<li class='err'>There are no stock items in the selected store.</li>"; continue; } if ($sel_frm == "stkcod") { $cods = "\n\t\t\t\t\t\t\t\t<select class='width:15' name='stkidss[]' onChange='javascript:document.form.submit();'>\n\t\t\t\t\t\t\t\t\t<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $cods .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $cods .= "</select> "; $descs = ""; } else { $descs = "<select class='width:15' name='stkidss[]' onChange='javascript:document.form.submit();'>"; $descs .= "<option value='-S' disabled selected>Select Description</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $descs .= "<option value='{$stk['stkid']}'>{$stk['stkdes']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $descs .= "</select> "; $cods = ""; } # put in drop down and warehouse $products .= "\n\t\t\t\t\t\t\t<input type='hidden' name='accountss[]' value='0'>\n\t\t\t\t\t\t\t<input type='hidden' name='descriptionss[]' value=''>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><input type='hidden' name='whidss[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t\t\t<td>{$cods}</td>\n\t\t\t\t\t\t\t\t<td>{$descs}</td>\n\t\t\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t\t\t\t<td><input type='hidden' name='amts[]' value='0.00'></td>\n\t\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t</tr>"; } } } } } else { if (!(isset($diffwhBtn) || isset($addnon))) { # check if setting exists db_connect(); $sql = "SELECT value FROM set WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'"; $Rslt = db_exec($sql) or errDie("Unable to check database for existing settings."); if (pg_numrows($Rslt) > 0) { $set = pg_fetch_array($Rslt); $whid = $set['value']; if (isset($wtd) && $wtd != 0) { $whid = $wtd; } # get selected warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$whid}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE whid = '{$whid}' AND blocked = 'n' AND div = '" . USER_DIV . "' ORDER BY stkcod ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { if (!isset($err)) { $err = ""; } $err .= "<li>There are no stock items in the selected warehouse.</li>"; } $stks = "\n\t\t\t\t\t<select class='width:15' name='stkidss[]' onChange='javascript:document.form.submit();'>\n\t\t\t\t\t\t<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $stks .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $stks .= "</select> "; $products .= "\n\t\t\t\t\t<input type='hidden' name='descriptionss[]' value=''>\n\t\t\t\t\t<input type='hidden' name='accountss[]' value='0'>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td><input type='hidden' name='whidss[]' value='{$whid}'>{$wh['whname']}</td>\n\t\t\t\t\t\t<td>{$stks}</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t</tr>"; } else { $products .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>{$whs}</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t</tr>"; } } else { if (isset($addnon)) { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); $Accounts = "\n\t\t\t\t<select name='accountss[]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>"; } $Accounts .= "</select>"; $products .= "\n\t\t\t\t<input type='hidden' name='whidss[]' value='{$FIRST_WH}'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}</td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[]'></td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtyss[]' value='1'></td>\n\t\t\t\t\t<td><input type='text' name='unitcosts[]' size='7'></td>\n\t\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t</tr>"; } } } /* -- start Listeners -- */ if (isset($diffwhBtn)) { $products .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$whs}</td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td>" . CUR . " 0.00</td>\n\t\t\t\t<td></td>\n\t\t\t</tr>"; } /* -- End Listeners -- */ $products .= "</table>"; /* --- End Products Display --- */ /* --- Start Some calculations --- */ # Calculate subtotal $SUBTOT = sprint($doc['subtot']); # Calculate subtotal $SUBTOT = sprint($doc['subtot']); /* --- End Some calculations --- */ /*--- Start checks --- */ // Which display method was selected if (isset($sel_frm) && $sel_frm == "stkdes") { $sel_frm_cod = ""; $sel_frm_des = "checked"; } else { $sel_frm_cod = "checked"; $sel_frm_des = ""; } /*--- Start checks --- */ $details_begin = "\n\t\t<center>\n\t\t<h3>New CallOut </h3>\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t<input type='hidden' name='key' value='update'>\n\t\t\t<input type='hidden' name='calloutid' value='{$calloutid}'>\n\t\t<table " . TMPL_tblDflts . " width='95%'>\n \t\t\t<tr>\n \t\t\t\t<td valign='top'>\n \t\t\t\t\t<div id='cust_selection'>"; if (empty($ajax_err) && (isset($cusnum) || AJAX)) { if (isset($cusnum)) { $OTS_OPT = onthespot_encode(SELF, "cust_selection", "deptid={$doc['deptid']}&letters={$letters}&cusnum={$cusnum}&calloutid={$calloutid}"); $custedit = "\n\t\t\t\t<td nowrap>\n\t\t\t\t\t<a href='javascript: popupSized(\"cust-edit.php?cusnum={$cusnum}&onthespot={$OTS_OPT}\", \"edit_cust\", 700, 630);'>\n\t\t\t\t\t\tEdit Customer Details\n\t\t\t\t\t</a>\n\t\t\t\t</td>"; } else { $custedit = ""; } $ajaxOut = "\n\t\t\t<input type='hidden' name='letters' value='{$letters}'>\n\t\t\t<input type='hidden' name='stkerr' value='{$stkerr}'>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'> Customer Details </th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Department</td>\n\t\t\t\t\t<td valign='center'>{$dept['deptname']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer</td>\n\t\t\t\t\t<td valign='center'>{$customers}</td>\n\t\t\t\t\t{$custedit}\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Customer Address</td>\n\t\t\t\t\t<td valign='center'>" . nl2br($cust['addr1']) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer VAT Number</td>\n\t\t\t\t\t<td>{$cust['vatnum']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Using</td>\n\t\t\t\t\t<td>Stock Code<input type='radio' name='sel_frm' value='stkcod' onChange='javascript:document.form.submit();' {$sel_frm_cod}><br>Stock Description<input type='radio' name='sel_frm' value='stkdes' onChange='javascript:document.form.submit();' {$sel_frm_des}></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; } else { db_conn("exten"); $sql = "SELECT * FROM departments WHERE div = '" . USER_DIV . "' ORDER BY deptname ASC"; $deptRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($deptRslt) < 1) { return "<li class='err'>There are no Departments found in Cubit."; } else { $depts = "<select id='deptid'>"; $depts .= "<option value='0'>All Departments</option>"; while ($dept = pg_fetch_array($deptRslt)) { $depts .= "<option value='{$dept['deptid']}'>{$dept['deptname']}</option>"; } $depts .= "</select>"; } if (!isset($ajax_err)) { $ajax_err = ""; } $ajaxOut = "\n\t\t\t<script>\n\t\t\t\tfunction updateCustSelection() {\n\t\t\t\t\tdeptid = getObject('deptid').value;\n\t\t\t\t\tletters = getObject('letters').value;\n\t\t\t\t\tajaxRequest('" . SELF . "', 'cust_selection', AJAX_SET, 'letters='+letters+'&deptid='+deptid+'&calloutid={$calloutid}');\n\t\t\t\t}\n\t\t\t</script>\n\n\t\t\t{$ajax_err}\n\t\t\t<table " . TMPL_tblDflts . " width='400'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>New Callout Document</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Select Department</td>\n\t\t\t\t\t<td valign='center'>{$depts}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>First Letters of customer</td>\n\t\t\t\t\t<td valign='center'><input type='text' size='5' id='letters' maxlength='5'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td> </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td valign='center'><input type='button' value='Update »' onClick='updateCustSelection();'></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; } if (isset($diffwhBtn) or isset($addprodBtn) or isset($addnon) or isset($saveBtn) or isset($upBtn) or isset($doneBtn)) { $jump_bot = "\n\t\t\t<script>\n\t\t\t\twindow.location.hash='bottom';\n\t\t\t</script>"; } else { $jump_bot = ""; } $details_end = "\n\t\t\t\t</div>\n\t\t\t</td>\n\t\t\t<td valign='top' align='right'>\n\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th colspan='2'>Callout Document Details</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Job Number</td>\n\t\t\t\t\t\t<td valign='center'>{$doc['calloutid']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Call Out Person</td>\n\t\t\t\t\t\t<td valign='center'>{$calloutps}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Date Service Required</td>\n\t\t\t\t\t\t<td valign='center'>" . mkDateSelect("call", $call_year, $call_month, $call_day) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Call Out Rate</td>\n\t\t\t\t\t\t<td valign='center' nowrap>" . CUR . " <input type='text' name='def_travel' value='{$doc['def_travel']}'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Labour Rate/Hour</td>\n\t\t\t\t\t\t<td valign='center' nowrap>" . CUR . " <input type='text' name='def_labour' value='{$doc['def_labour']}'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td> </td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='2'>{$products}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='4'><textarea name='sign' cols='80' rows='2'>{$doc['sign']}</textarea></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th width='25%'>Quick Links</th>\n\t\t\t\t\t<th width='25%'>Description Of Callout</th>\n\t\t\t\t\t<th width='25%'>Comments</th>\n\t\t\t\t\t<td rowspan='5' valign='top' width='50%'>{$error}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='" . bg_class() . "'><a href='callout-new.php'>New Callout Document</a></td>\n\t\t\t\t\t<td class='" . bg_class() . "' rowspan='4' align='center' valign='top'><textarea name='calloutdescrip' rows='4' cols='20'>{$doc['calloutdescrip']}</textarea></td>\n\t\t\t\t\t<td class='" . bg_class() . "' rowspan='4' align='center' valign='top'><textarea name='comm' rows='4' cols='20'>{$doc['comm']}</textarea></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='callout-view.php'>View Callout Documents</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t</table>\n\t\t\t</td>\n\t\t\t<td align='right'></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align='right'>\n\t\t\t\t<input name='diffwhBtn' type='submit' value='Different Store'> |\n\t\t\t\t<input name='addprodBtn' type='submit' value='Add Product'> |\n\t\t\t\t<input name='addnon' type='submit' value='Add Non stock Product'> |\n\t\t\t\t<input type='submit' name='saveBtn' value='Save'></td><td> |\n\t\t\t\t<input type='submit' name='upBtn' value='Update'>{$done}\n\t\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t\t<a name='bottom'>\n\t\t</form>\n\t\t</center>\n\t\t{$jump_bot}"; if (AJAX) { return $ajaxOut; } else { return "{$details_begin}{$ajaxOut}{$details_end}"; } }
function details($_POST, $error = "") { # Get vars extract($_POST); # validate input require_lib("validate"); $v = new validate(); if (isset($invid)) { $v->isOk($invid, "num", 1, 20, "Invalid invoice number."); } if (isset($letter)) { $v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters."); } if (isset($deptid)) { $v->isOk($deptid, "num", 1, 20, "Invalid department number."); } if (isset($sel_frm)) { $v->isOk($sel_frm, "string", 6, 6, "Invalid select from selection."); } # display errors, if any if ($v->isError()) { $error = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $error .= "<li class='err'>" . $e["msg"] . "</li>"; } return $error . view_err($_POST); } if (isset($deptid) && isset($letters)) { db_connect(); if ($deptid == "0") { $searchdept = ""; } else { $searchdept = "deptid = '{$deptid}' AND "; } # Query server for customer info $sql = "SELECT cusnum, cusname, surname FROM customers WHERE {$searchdept} location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND blocked != 'yes' AND div = '" . USER_DIV . "' ORDER BY surname"; $custRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($custRslt) < 1) { $ajax_err = "<li class='err'>No customer names starting with <b>{$letters}</b> in database.</li>"; //return view_err($_POST, $err); } } if (!isset($deptid)) { $deptid = 2; } else { if (isset($invid)) { db_conn("cubit"); $sql = "UPDATE invoices SET deptid='{$deptid}' WHERE invid='{$invid}' AND deptid<>'{$deptid}'"; db_exec($sql) or errDie("Error updating invoice department."); } } if (!isset($invid)) { $invid = create_dummy($deptid); } if (!isset($stkerr)) { $stkerr = "0,0"; } if (!isset($done)) { $done = ""; } if (!isset($cust_del_addr)) { $cust_del_addr = ""; } if (!isset($sel_frm)) { $sel_frm = "stkcod"; } # Get invoice info db_connect(); $sql = "SELECT * FROM invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get invoice information"); if (pg_numrows($invRslt) < 1) { return "<li class='err'>Invoice Not Found</li>"; } $inv = pg_fetch_array($invRslt); if (!isset($branch)) { $branch = $inv['branch']; } # Check if invoice has been printed if ($inv['printed'] == "y") { $error = "<li class='err'> Error : Invoice number <b>{$invid}</b> has already been printed.</li>"; $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; return $error; } # Get department db_conn("exten"); $sql = "SELECT * FROM departments WHERE deptid = '{$inv['deptid']}' AND div = '" . USER_DIV . "'"; $deptRslt = db_exec($sql); if (pg_numrows($deptRslt) < 1) { $dept['deptname'] = "<li class='err'>Department not Found.</li>"; } else { $dept = pg_fetch_array($deptRslt); } # Get selected Customer info if (isset($letters)) { db_connect(); $sql = "SELECT * FROM customers WHERE cusnum = '{$inv['cusnum']}' AND location != 'int' AND div = '" . USER_DIV . "'"; $custRslt = db_exec($sql) or errDie("Unable to view customer"); if (pg_numrows($custRslt) < 1) { if ($inv['deptid'] == 0) { $searchdept = ""; } else { $searchdept = "deptid = '{$inv['deptid']}' AND "; } # Query server for customer info $sql = "SELECT cusnum, cusname, surname, accno FROM customers WHERE {$searchdept} location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND blocked != 'yes' AND div = '" . USER_DIV . "' ORDER BY surname"; $custRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($custRslt) < 1) { $ajax_err = "<li class='err'>No customer names starting with <b>{$letters}</b> in database.</li>"; //return view_err($_POST, $err); } else { $customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>"; if (pg_numrows($custRslt) == 1) { $inv['cusnum'] = pg_fetch_result($custRslt, 0, 0); } else { $customers .= "<option value='-S' selected>Select Customer</option>"; } while ($cust = pg_fetch_array($custRslt)) { $customers .= "<option value='{$cust['cusnum']}'>{$cust['cusname']} {$cust['surname']} ({$cust['accno']})</option>"; } $customers .= "</select>"; } # Take care of the unset vars $cust['addr1'] = ""; $cust['cusnum'] = ""; $cust['vatnum'] = ""; $cust['accno'] = ""; $cust_del_addr = ""; $branchdrop = "<input type='hidden' name='branch' value='0'>"; } else { $cust = pg_fetch_array($custRslt); #override address if ($branch != 0) { $get_addr = "SELECT branch_descrip FROM customer_branches WHERE id = '{$branch}' AND div = '" . USER_DIV . "' LIMIT 1"; $run_addr = db_exec($get_addr); if (pg_numrows($run_addr) < 1) { #address missing ... do nothing } else { $arr = pg_fetch_array($run_addr); $cust['addr1'] = $arr['branch_descrip']; if ($inv['del_addr'] != $arr['branch_descrip']) { $update_addr = "UPDATE invoices SET del_addr = '{$arr['branch_descrip']}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; } } } #if the del_addr of invoice if empty, add the customer's entry and display button so user can edit anyway if (strlen($inv['del_addr']) < 1) { $cust_del_addr = $cust['del_addr1']; } else { $cust_del_addr = $inv['del_addr']; } $sql = "SELECT cusnum, cusname, surname FROM customers WHERE deptid = '{$inv['deptid']}' AND location != 'int' AND lower(surname) LIKE lower('{$letters}%') AND blocked != 'yes' AND div = '" . USER_DIV . "' ORDER BY surname"; $cusRslt = db_exec($sql) or errDie("Unable to view customers"); # Moarn if customer account has been blocked if ($cust['blocked'] == 'yes') { $error .= "<li class='err'>Error : Selected customer account has been blocked.</li>"; } // $customers = "<input type=hidden name=cusnum value='$cust[cusnum]'>$cust[cusname] $cust[surname]"; $cusnum = $cust['cusnum']; $customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>"; // $customers .= "<option value='-S' selected>Select Customer</option>"; while ($cus = pg_fetch_array($cusRslt)) { $sel = ""; if ($cust['cusnum'] == $cus['cusnum']) { $sel = "selected"; } $customers .= "<option value='{$cus['cusnum']}' {$sel}>{$cus['cusname']} {$cus['surname']}</option>"; } $customers .= "</select>"; #get list of branches $get_branches = "SELECT * FROM customer_branches WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $run_branches = db_exec($get_branches); if (pg_numrows($run_branches) < 1) { $branchdrop = "<input type='hidden' name='branch' value='0'>No Branches For This Customer"; } else { $branchdrop = "<select name='branch' onChange='javascript:document.form.submit();'>"; $branchdrop .= "<option value='0'>Head Office</option>"; while ($barr = pg_fetch_array($run_branches)) { $sel2 = ""; if ($barr['id'] == $branch) { $sel2 = "selected"; } $branchdrop .= "<option {$sel2} value='{$barr['id']}'>{$barr['branch_name']}</option>"; } $branchdrop .= "</select>"; } } } /* --- Start Drop Downs --- */ # Select warehouse db_conn("exten"); //old //$whs = "<select name='whidss[]' onChange='javascript:document.form.submit();'>"; //fixes broken new store function //STORE1 $whs = "<select name='whidss[]'>"; $sql = "SELECT * FROM warehouses WHERE div = '" . USER_DIV . "' ORDER BY whname ASC"; $whRslt = db_exec($sql); if (pg_numrows($whRslt) < 1) { return "<li class='err'> There are no Stores found in Cubit.</li>"; } else { $whs .= "<option value='-S' disabled selected>Select Store</option>"; while ($wh = pg_fetch_array($whRslt)) { $whs .= "<option value='{$wh['whid']}'>({$wh['whno']}) {$wh['whname']}</option>"; } } $whs .= "</select>"; // Is the customer linked to a sales rep if (!empty($cust["sales_rep"])) { db_conn("exten"); $sql = "SELECT salesp FROM salespeople WHERE salespid='{$cust['sales_rep']}'"; $sr_rslt = db_exec($sql) or errDie("Unable to retrieve sales rep from Cubit."); $salespname = pg_fetch_result($sr_rslt, 0); $salesps = "<input type='hidden' name='salespn' value='{$salespname}'><b>[{$salespname}]</b>"; } else { db_conn("exten"); $sql = "SELECT * FROM salespeople WHERE div = '" . USER_DIV . "' ORDER BY salesp ASC"; $salespRslt = db_exec($sql) or errDie("Unable to get sales people."); if (pg_numrows($salespRslt) < 1) { return "<li class='err'> There are no Sales People found in Cubit.</li>"; } else { $salesps = "<select name='salespn'>"; while ($salesp = pg_fetch_array($salespRslt)) { if ($salesp['salesp'] == $inv['salespn']) { $sel = "selected"; } else { $sel = ""; } $salesps .= "<option value='{$salesp['salesp']}' {$sel}>{$salesp['salesp']}</option>"; } $salesps .= "</select>"; } } # Days drop downs $days = array("0" => "0", "7" => "7", "14" => "14", "30" => "30", "60" => "60", "90" => "90", "120" => "120"); $termssel = extlib_cpsel("terms", $days, $inv['terms']); # Keep the charge vat option stable if ($inv['chrgvat'] == "inc") { $chin = "checked=yes"; $chex = ""; $chno = ""; } elseif ($inv['chrgvat'] == "exc") { $chin = ""; $chex = "checked=yes"; $chno = ""; } else { $chin = ""; $chex = ""; $chno = "checked=yes"; } # Format date list($inv_date_year, $inv_date_month, $inv_date_day) = explode("-", $inv['odate']); /* --- End Drop Downs --- */ /* --- Start Products Display --- */ # Select all products $products = "\n\t\t<table " . TMPL_tblDflts . "' width='100%'>\n\t\t\t<tr>\n\t\t\t\t<th>STORE</th>\n\t\t\t\t<th>ITEM NUMBER</th>\n\t\t\t\t<th>VAT CODE</th>\n\t\t\t\t<th>SERIAL NO.</th>\n\t\t\t\t<th>DESCRIPTION</th>\n\t\t\t\t<th>QTY</th>\n\t\t\t\t<th>UNIT PRICE</th>\n\t\t\t\t<th>UNIT DISCOUNT</th>\n\t\t\t\t<th>AMOUNT</th>\n\t\t\t\t<th>Remove</th>\n\t\t\t<tr>"; # get selected stock in this invoice db_connect(); $sql = "SELECT * FROM inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $i = 0; $key = 0; $ai = 0; while ($stkd = pg_fetch_array($stkdRslt)) { $stkd['account'] += 0; if ($stkd['account'] != 0) { # Keep track of selected stock amounts $stkd["amt"] = sprint($stkd["amt"]); $amts[$i] = $stkd['amt']; $i++; $Accounts = "\n\t\t\t\t<select name='accounts[{$ai}]'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; $useaccdrop = getCSetting("USE_NON_STOCK_ACCOUNTS"); if (isset($useaccdrop) and $useaccdrop == "yes") { db_connect(); $acc_sql = "SELECT * FROM non_stock_account_list ORDER BY accname"; $run_acc = db_exec($acc_sql) or errDie("Unable to get account information."); if (pg_numrows($run_acc) > 0) { while ($acc = pg_fetch_array($run_acc)) { if ($acc['accid'] == $stkd['account']) { $Accounts .= "<option value='{$acc['accid']}' selected>{$acc['accname']}</option>"; } else { $Accounts .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>"; } } $Accounts .= "</select>"; } } else { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); while ($ad = pg_fetch_array($Ri)) { if ($ad['accid'] == $stkd['account']) { $sel = "selected"; } else { $sel = ""; } if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}' {$sel}>{$ad['accname']}</option>"; } } $Accounts .= "</select>"; $sernos = "\n\t\t\t\t<input type='hidden' name='sernos[{$ai}]' value='{$stkd['serno']}'>\n\t\t\t\t<input type='hidden' name='sernos_ss[{$ai}]' value='{$stkd['serno']}'>"; # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[{$ai}]' value='{$stkd['qty']}'>"; $viewcost = "<input type='text' size='8' name='unitcost[{$ai}]' value='{$stkd['unitcost']}'>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodes[{$ai}]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stkd['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in product $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>\n\t\t\t\t\t\t{$Accounts}\n\t\t\t\t\t\t<input type='hidden' name='whids[{$ai}]' value='{$stkd['whid']}'>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td><input type='hidden' name='stkids[{$ai}]' value='{$stkd['stkid']}'>{$Vatcodes}</td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptions[{$ai}]' value='{$stkd['description']}'> {$sernos}</td>\n\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t<td><input type='hidden' name='disc[{$ai}]' value='{$stkd['disc']}'><input type='hidden' name='discp[{$ai}]' value='{$stkd['discp']}'></td>\n\t\t\t\t\t<td nowrap><input type='hidden' name='amt[{$ai}]' value='{$stkd['amt']}'> " . CUR . " {$stkd['amt']}</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[{$ai}]' value='{$key}'></td>\n\t\t\t\t</tr>"; $key++; ++$ai; } else { # Keep track of selected stock amounts $amts[$i] = $stkd['amt']; $i++; # Get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stkd['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # Get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); # Serial number if ($stk['serd'] == 'yes' && ($inv['serd'] == 'n' || $stkd["serno"] == "")) { $sers = ext_getavserials($stkd['stkid']); $sernos = "<select name='sernos[{$ai}]'>"; foreach ($sers as $skey => $ser) { $sernos .= "<option value='{$ser['serno']}'>{$ser['serno']}</option>"; } $sernos .= "</select>\n\t\t\t\t\t<input type='hidden' name='sernos_ss[]' value='*_*_*CUBIT_SERIAL_SELECT_BOX*_*_*' />"; } else { $sernos = "\n\t\t\t\t\t<input type='hidden' name='sernos_ss[]' value='{$stkd['ss']}' />\n\t\t\t\t\t<input type='hidden' name='sernos[{$ai}]' value='{$stkd['serno']}'>{$stkd['ss']}"; } # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtys[{$ai}]' value='{$stkd['qty']}'>"; if ($stk['serd'] == 'yes') { $qtyin = "<input type='hidden' size='3' name='qtys[{$ai}]' value='{$stkd['qty']}'>{$stkd['qty']}"; } # check permissions if (perm("invoice-unitcost-edit.php")) { $viewcost = "<input type='text' size='8' name='unitcost[{$ai}]' value='{$stkd['unitcost']}'>"; } else { $viewcost = "<input type='hidden' size='8' name='unitcost[{$ai}]' value='{$stkd['unitcost']}'>{$stkd['unitcost']}"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodes[{$ai}]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stkd['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in product $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<input type='hidden' name='accounts[{$ai}]' value='0'>\n\t\t\t\t\t\t<input type='hidden' name='descriptions[{$ai}]' value=''>\n\t\t\t\t\t\t<input type='hidden' name='whids[{$ai}]' value='{$stkd['whid']}'>{$wh['whname']}\n\t\t\t\t\t</td>\n\t\t\t\t\t<td><input type='hidden' name='stkids[]' value='{$stkd['stkid']}'><a href='#bottom' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t<td>{$sernos}</td>\n\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t<td><input type='text' size='4' name='disc[{$ai}]' value='{$stkd['disc']}'> OR <input type='text' size='4' name='discp[{$ai}]' value='{$stkd['discp']}' maxlength='5'>%</td>\n\t\t\t\t\t<td nowrap><input type='hidden' name='amt[{$ai}]' value='{$stkd['amt']}'> " . CUR . " {$stkd['amt']}</td>\n\t\t\t\t\t<td><input type='checkbox' name='remprod[{$ai}]' value='{$key}'></td>\n\t\t\t\t</tr>"; $key++; ++$ai; } } # Look above(remprod keys) $keyy = $key; # Look above(if i = 0 then there are no products) if ($i == 0) { $done = ""; } else { $SCROLL = "yes"; } # check if stock warehouse was selected if (isset($whidss)) { foreach ($whidss as $key => $whid) { if (isset($stkidss[$key]) && $stkidss[$key] != "-S" && isset($cust['pricelist'])) { # skip if not selected if ($whid == "-S") { continue; } # Get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkidss[$key]}' AND div = '" . USER_DIV . "' ORDER BY stkcod ASC"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); # Get selected warehouse name db_conn("exten"); $sql = "SELECT whid, whname FROM warehouses WHERE whid = (select whid from cubit.stock where stkid = '{$stk['stkid']}' limit 1) AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); if ($stk['serd'] == 'yes') { $sers = ext_getavserials($stkidss[$key]); $sernos = "<select name='sernos[]' onChange='javascript:document.form.submit();'>"; foreach ($sers as $skey => $ser) { $sernos .= "<option value='{$ser['serno']}'>{$ser['serno']}</option>"; } $sernos .= "</select>\n\t\t\t\t\t\t<input type='hidden' name='sernos_ss[]' value='*_*_*CUBIT_SERIAL_SELECT_BOX*_*_*' />"; } else { $sernos = "\n\t\t\t\t\t\t<input type='hidden' name='sernos_ss[]' value=''>\n\t\t\t\t\t\t<input type='hidden' name='sernos[{$ai}]' value=''>"; } # Get price from price list if it is set if (isset($cust['pricelist'])) { # get selected stock in this warehouse db_conn("exten"); $sql = "SELECT price FROM plist_prices WHERE listid = '{$cust['pricelist']}' AND stkid = '{$stk['stkid']}' AND div = '" . USER_DIV . "'"; $plRslt = db_exec($sql); if (pg_numrows($plRslt) > 0) { $pl = pg_fetch_array($plRslt); $stk['selamt'] = $pl['price']; } } /* -- Start Some Checks -- */ # check if they are selling too much if ($stk['units'] - $stk['alloc'] < $qtyss[$key]) { if (!in_array($stk['stkid'], explode(",", $stkerr))) { if ($stk['type'] != 'lab') { $stkerr .= ",{$stk['stkid']}"; $error .= "<li class='err'>Warning : Item number <b>{$stk['stkcod']}</b> does not have enough items available.</li>"; } } } if ($stk['units'] <= $stk['minlvl'] && $stk['minlvl'] != 0) { $error .= "<li class='err'>{$stk['stkcod']} is below minimum level, please notify stock controller.</li>"; } /* -- End Some Checks -- */ # Calculate the Discount discount if ($discs[$key] < 1) { if ($discps[$key] > 0) { $discs[$key] = round($discps[$key] / 100 * $stk['selamt'], 2); } } else { $discps[$key] = round($discs[$key] * 100 / $stk['selamt'], 2); } # Calculate amount $amt[$key] = $qtyss[$key] * ($stk['selamt'] - $discs[$key]); # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtemp' value='{$qtyss[$key]}'>"; if ($stk['serd'] == 'yes') { $qtyin = "<input type='hidden' size='3' name='qtemp' value='{$qtyss[$key]}'>{$qtyss[$key]}"; } #clean some vars $stk['selamt'] = sprint($stk['selamt']); $amt[$key] = sprint($amt[$key]); # Check permissions if (perm("invoice-unitcost-edit.php")) { $viewcost = "<input type='text' size='8' name='unitcost[{$ai}]' value='{$stk['selamt']}'>"; } else { $viewcost = "<input type='hidden' size='8' name='unitcost[{$ai}]' value='{$stk['selamt']}'>{$stk['selamt']}"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t<select name='vatcodes[{$ai}]'>\n\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($stk['vatcode'] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in selected warehouse and stock $products .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type='hidden' name='accounts[{$ai}]' value='0'>\n\t\t\t\t\t\t\t<input type='hidden' name='descriptions[{$ai}]' value=''>\n\t\t\t\t\t\t\t<input type='hidden' name='whids[]' value='{$wh['whid']}'>{$wh['whname']}\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td><input type='hidden' name='stkids[{$ai}]' value='{$stk['stkid']}'><a href='#bottom' onclick='openwindow(\"stock-amt-det.php?stkid={$stk['stkid']}\")'>{$stk['stkcod']}</a></td>\n\t\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t\t<td>{$sernos}</td>\n\t\t\t\t\t\t<td>" . extlib_rstr($stk['stkdes'], 30) . "</td>\n\t\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t\t<td><input type='text' size='4' name='disc[{$ai}]' value='{$discs[$key]}'> OR <input type='text' size='4' name='discp[{$ai}]' value='{$discps[$key]}' maxlength='5'>%</td>\n\t\t\t\t\t\t<td nowrap><input type='hidden' name='amt[{$ai}]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[{$ai}]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; ++$ai; } elseif (isset($accountss[$key]) && $accountss[$key] != "0" && isset($cust['pricelist'])) { db_conn('core'); $Sl = "SELECT * FROM accounts WHERE accid='{$accountss[$key]}'"; $Ri = db_exec($Sl) or errDie("Unable to get account data."); if (pg_num_rows($Ri) < 1) { return "invalid."; } $ad = pg_fetch_array($Ri); # Calculate amount $amt[$key] = sprint($qtyss[$key] * $unitcosts[$key]); # Input qty if not serialised $qtyin = "<input type='text' size='3' name='qtemp' value='{$qtyss[$key]}'>"; # Check permissions $viewcost = "<input type='text' size='8' name='unitcost[{$ai}]' value='{$unitcosts[$key]}'>"; db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t<select name='vatcodes[{$ai}]'>\n\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vatcodess[$key] == $vd['id']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # Put in selected warehouse and stock $products .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td colspan='2'>\n\t\t\t\t\t\t\t{$ad['accname']}\n\t\t\t\t\t\t\t<input type='hidden' name='accounts[{$ai}]' value='{$accountss[$key]}'>\n\t\t\t\t\t\t\t<input type='hidden' name='whids[{$ai}]' value='0'>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td>{$Vatcodes}<input type='hidden' name='stkids[{$ai}]' value='0'></td>\n\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='descriptions[{$ai}]' value='{$descriptionss[$key]}'></td>\n\t\t\t\t\t\t<td>{$qtyin}</td>\n\t\t\t\t\t\t<td>{$viewcost}</td>\n\t\t\t\t\t\t<td><input type='hidden' name='disc[{$ai}]' value='0'><input type='hidden' name='discp[{$ai}]' value='0'></td>\n\t\t\t\t\t\t<td nowrap><input type='hidden' name='amt[{$ai}]' value='{$amt[$key]}'> " . CUR . " {$amt[$key]}</td>\n\t\t\t\t\t\t<td><input type='checkbox' name='remprod[{$ai}]' value='{$keyy}'></td>\n\t\t\t\t\t</tr>"; $keyy++; ++$ai; } else { # skip if not selected if ($whid == "-S") { continue; } if (!isset($addnon)) { if ($filter_store != "0") { # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$filter_store}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); } if (isset($ria) and $ria != "") { $len = strlen($ria); if ($ria == "Show All") { $Wh = ""; $ria = ""; } else { $Wh = "AND (lower(stkdes) LIKE lower('%{$ria}%')) OR (lower(stkcod) LIKE lower('%{$ria}%'))"; $ria = ""; } } else { $Wh = "AND FALSE"; $ria = ""; } $check_setting = getCSetting("OPTIONAL_STOCK_FILTERS"); if (isset($check_setting) and $check_setting == "yes") { if (isset($filter_class) and $filter_class != "0") { $Wh .= " AND prdcls = '{$filter_class}'"; } if (isset($filter_cat) and $filter_cat != "0") { $Wh .= " AND catid = '{$filter_cat}'"; } } if (isset($filter_store) and $filter_store != "0") { $Wh .= " AND whid = '{$filter_store}'"; } # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE blocked = 'n' AND div = '" . USER_DIV . "' {$Wh} ORDER BY {$sel_frm} ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { $error .= "<li class='err'>There are no stock items in the selected warehouse."; continue; } if (pg_numrows($stkRslt) == 1) { $ex = "selected"; $reload = TRUE; $send_override = "<input type='hidden' name='stkidss[{$ai}]' value='" . pg_fetch_result($stkRslt, 0, 0) . "'><script>document.form.submit();</script>"; } else { $ex = ""; $reload = FALSE; } if ($sel_frm == "stkcod") { $cods = "<select name='stkidss[{$ai}]' onChange='javascript:document.form1.submit();'>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { // Check if this stock item has been blocked //pointless, as we only get non blocked stock ... //if (stock_is_blocked($stk["stkid"])) { // continue; //} $cods .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $cods .= "</select> "; $descs = ""; } else { $descs = "<select style='width:250px'name='stkidss[{$ai}]' onChange='javascript:document.form.submit();'>"; $descs .= "<option value='-S' disabled selected>Select Description</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { // Check if this stock item has been blocked //pointless, as ge only get non blocked stock // if (stock_is_blocked($stk["stkid"])) { // continue; // } $descs .= "<option value='{$stk['stkid']}'>{$stk['stkdes']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $descs .= "</select> "; $cods = ""; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t\t<select name='vatcodess[{$ai}]'>\n\t\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; # put in drop down and warehouse $products .= "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<input type='hidden' name='accountss[{$ai}]' value='0'>\n\t\t\t\t\t\t\t\t<input type='hidden' name='descriptionss[{$ai}]' value=''>\n\t\t\t\t\t\t\t\t<input type='hidden' name='whidss[{$ai}]' value='{$filter_store}'>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>{$cods}</td>\n\t\t\t\t\t\t\t<td><input type='hidden' name='vatcodess' value='0'></td>\n\t\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t\t<td>{$descs}</td>\n\t\t\t\t\t\t\t<td><input type='hidden' size='3' name='qtyss[{$ai}]' value='1'>1</td>\n\t\t\t\t\t\t\t<td> </td>\n\t\t\t\t\t\t\t<td><input type='text' size='4' name='discs[{$ai}]' value='0'> OR <input type='text' size='4' name='discps[{$ai}]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t\t\t<td nowrap><input type='hidden' name='amts[{$ai}]' value='0.00'>" . CUR . " 0.00</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t</tr>"; ++$ai; } else { $Accounts = "\n\t\t\t\t\t\t<select name='accountss[{$ai}]' onChange='javascript:document.form.submit();'>\n\t\t\t\t\t\t\t<option value='0'>Select Account</option>"; $useaccdrop = getCSetting("USE_NON_STOCK_ACCOUNTS"); if (isset($useaccdrop) and $useaccdrop == "yes") { db_connect(); $acc_sql = "SELECT * FROM non_stock_account_list ORDER BY accname"; $run_acc = db_exec($acc_sql) or errDie("Unable to get account information."); if (pg_numrows($run_acc) > 0) { while ($acc = pg_fetch_array($run_acc)) { $Accounts .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>"; } $Accounts .= "</select>"; } } else { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>"; } $Accounts .= "</select>"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t\t\t<select name='vatcodess[{$ai}]'>\n\t\t\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $products .= "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td colspan='2'>\n\t\t\t\t\t\t\t\t{$Accounts}\n\t\t\t\t\t\t\t\t<input type='hidden' name='whidss[{$ai}]' value='1'>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<inpu type='hidden' name='stkidss[{$ai}]' value=''>\n\t\t\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[{$ai}]'></td>\n\t\t\t\t\t\t\t<td><input type='text' size='3' name='qtyss[{$ai}]' value='1'></td>\n\t\t\t\t\t\t\t<td><input type='text' name='unitcosts[{$ai}]' size='7'></td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td nowrap>" . CUR . " 0.00</td>\n\t\t\t\t\t\t\t<td><input type='hidden' name='discs[{$ai}]' value='0'><input type='hidden' name='discps[{$ai}]' value='0'></td>\n\t\t\t\t\t\t</tr>"; ++$ai; } } } } else { #HAX ! if (!isset($addnon) && !isset($upBtn)) { if (isset($ria) and $ria != "") { $len = strlen($ria); if ($ria == "Show All") { $Wh = ""; $ria = ""; } else { $Wh = "AND (lower(stkdes) LIKE lower('%{$ria}%')) OR (lower(stkcod) LIKE lower('%{$ria}%'))"; $ria = ""; } } else { $Wh = "AND FALSE"; $ria = ""; } $check_setting = getCSetting("OPTIONAL_STOCK_FILTERS"); if (isset($check_setting) and $check_setting == "yes") { if (isset($filter_class) and $filter_class != "0") { $Wh .= " AND prdcls = '{$filter_class}'"; } if (isset($filter_cat) and $filter_cat != "0") { $Wh .= " AND catid = '{$filter_cat}'"; } } if (isset($filter_store) and $filter_store != "0") { $Wh .= " AND whid = '{$filter_store}'"; } # get stock on this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE blocked = 'n' AND div = '" . USER_DIV . "' {$Wh} ORDER BY {$sel_frm} ASC"; $stkRslt = db_exec($sql) or errDie("Unable to retrieve stocks from database."); if (pg_numrows($stkRslt) < 1) { if (!isset($err)) { $err = ""; } $err .= "<li>There are no stock items in the selected store.</li>"; //ontinue; } if (pg_numrows($stkRslt) == 1) { $reload = TRUE; $send_override = "<input type='hidden' name='stkidss[{$ai}]' value='" . pg_fetch_result($stkRslt, 0, 0) . "'>"; } else { $reload = FALSE; $send_override = ""; } if ($sel_frm == "stkcod") { $cods = "<select name='stkidss[{$ai}]' onChange='javascript:document.form.submit();'>"; // $cods .= "<option value='-S' disabled selected>Select Number</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $cods .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $cods .= "</select> "; $descs = ""; } else { $descs = "<select style='width:250px' name='stkidss[{$ai}]' onChange='javascript:document.form.submit();'>"; $descs .= "<option value='-S' disabled selected>Select Description</option>"; $count = 0; while ($stk = pg_fetch_array($stkRslt)) { $descs .= "<option value='{$stk['stkid']}'>{$stk['stkdes']} (" . sprint3($stk['units'] - $stk['alloc']) . ")</option>"; } $descs .= "</select> "; $cods = ""; } $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<input type='hidden' name='accountss[{$ai}]' value='0'>\n\t\t\t\t\t\t<input type='hidden' name='descriptionss[{$ai}]' value=''>\n\t\t\t\t\t\t<input type='hidden' name='vatcodess[{$ai}]' value=''>\n\t\t\t\t\t\t<input type='hidden' name='whidss[{$ai}]' value='{$filter_store}'>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td>{$cods}</td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td>{$descs}</td>\n\t\t\t\t\t<td><input type='hidden' size='3' name='qtyss[{$ai}]' value='1'>1</td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td><input type='text' size='4' name='discs[{$ai}]' value='0'> OR <input type='text' size='4' name='discps[{$ai}]' value='0' maxlength='5'>%</td>\n\t\t\t\t\t<td nowrap>" . CUR . " 0.00</td>\n\t\t\t\t\t<td></td>\n\t\t\t\t</tr>"; ++$ai; } elseif (isset($addnon)) { $Accounts = "\n\t\t\t\t<select name='accountss[{$ai}]' onChange='javascript:document.form.submit();'>\n\t\t\t\t\t<option value='0'>Select Account</option>"; $useaccdrop = getCSetting("USE_NON_STOCK_ACCOUNTS"); if (isset($useaccdrop) and $useaccdrop == "yes") { db_connect(); $acc_sql = "SELECT * FROM non_stock_account_list ORDER BY accname"; $run_acc = db_exec($acc_sql) or errDie("Unable to get account information."); if (pg_numrows($run_acc) > 0) { while ($acc = pg_fetch_array($run_acc)) { $Accounts .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>"; } $Accounts .= "</select>"; } } else { db_conn('core'); $Sl = "SELECT accid,topacc,accnum,accname FROM accounts WHERE acctype='I' ORDER BY accname"; $Ri = db_exec($Sl) or errDie("Unable to get accounts."); while ($ad = pg_fetch_array($Ri)) { if (isb($ad['accid'])) { continue; } $Accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>"; } $Accounts .= "</select>"; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t\t\t<select name='vatcodess[{$ai}]'>\n\t\t\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['del'] == "Yes") { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; $products .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='2'>{$Accounts}<input type='hidden' name='whidss[{$ai}]' value='1'></td>\n\t\t\t\t\t<inpu type='hidden' name='stkidss[{$ai}]' value=''>\n\t\t\t\t\t<td>{$Vatcodes}</td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td><input type='text' size='20' name='descriptionss[{$ai}]'></td>\n\t\t\t\t\t<td><input type='text' size='3' name='qtyss[{$ai}]' value='1'></td>\n\t\t\t\t\t<td><input type='text' name='unitcosts[{$ai}]' size='7'></td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td nowrap>" . CUR . " 0.00</td>\n\t\t\t\t\t<td><input type='hidden' name='discs[{$ai}]' value='0'><input type='hidden' name='discps[{$ai}]' value='0' ></td>\n\t\t\t\t</tr>"; ++$ai; } } $products .= "</table>"; /* --- End Products Display --- */ /* --- Start Some calculations --- */ # Calculate subtotal $SUBTOT = sprint($inv['subtot']); # Calculate tradediscm if ($inv['traddisc'] > 0) { $traddiscm = sprint($inv['traddisc'] / 100 * $inv['total']); } else { $traddiscm = "0.00"; } $VATP = TAX_VAT; # Calculate subtotal $SUBTOT = sprint($inv['subtot']); $VAT = sprint($inv['vat']); $TOTAL = sprint($inv['total']); $inv['delchrg'] = sprint($inv['delchrg']); /* --- End Some calculations --- */ /*--- Start checks --- */ # check only if the customer is selected if (isset($cusnum) && $cusnum != "-S") { #check againg credit limit if ($TOTAL + $cust['balance'] > $cust['credlimit']) { $error .= "<li class='err'>Warning : Customers Credit limit of <b>" . CUR . " " . sprint($cust["credlimit"]) . "</b> has been exceeded"; #limit reached ... check for warn/block db_conn("cubit"); $get_check = "SELECT value FROM set WHERE label = 'CUST_INV_WARN' LIMIT 1"; $run_check = db_exec($get_check) or errDie("Unable to get credit limit response setting"); if (pg_numrows($run_check) < 1) { #no setting ? do nothing .... } else { $sarr = pg_fetch_array($run_check); if ($sarr['value'] == "block") { #block account ... $done = ""; } } # Check permissions if (!perm("invoice-limit-override.php")) { $done = ""; } } $avcred = $cust['credlimit'] - $cust['balance']; } else { $avcred = "0.00"; } /*--- Start checks --- */ db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $sc = "checked"; } else { $sc = ""; } $sales = "\n\t\t<td>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<td>{$salesps}</td>\n\t\t\t\t\t<td>Print</td>\n\t\t\t\t\t<td><input type='checkbox' name='printsales' {$sc}></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>"; $inv['delvat'] += 0; if ($inv['delvat'] == 0) { $Sl = "SELECT * FROM vatcodes WHERE del='Yes'"; $Ri = db_exec($Sl) or errDie("Unable to get data."); $vd = pg_fetch_array($Ri); $inv['delvat'] = $vd['id']; } db_conn('cubit'); $Sl = "SELECT * FROM vatcodes ORDER BY code"; $Ri = db_exec($Sl) or errDie("Unable to get vat codes"); $Vatcodes = "\n\t\t<select name='delvat'>\n\t\t\t<option value='0'>Select</option>"; while ($vd = pg_fetch_array($Ri)) { if ($vd['id'] == $inv['delvat']) { $sel = "selected"; } else { $sel = ""; } $Vatcodes .= "<option value='{$vd['id']}' {$sel}>{$vd['code']}</option>"; } $Vatcodes .= "</select>"; db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='Delivery Note'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $chp = "checked"; } else { $chp = ""; } if (empty($inv["comm"])) { db_conn("cubit"); $sql = "SELECT value FROM settings WHERE constant='DEFAULT_COMMENTS'"; $cmntRslt = db_exec($sql) or errDie("Unable to retrieve the default comment from Cubit."); $comm = base64_decode(pg_fetch_result($cmntRslt, 0)); } else { $comm = $inv["comm"]; } if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } // Which display method was selected if (isset($sel_frm) && $sel_frm == "stkdes") { $sel_frm_cod = ""; $sel_frm_des = "checked"; } else { $sel_frm_cod = "checked"; $sel_frm_des = ""; } // Delivery Date if (!empty($inv["deldate"])) { $deldate = explode("-", $inv["deldate"]); } else { $trans_date_setting = getCSetting("USE_TRANSACTION_DATE"); if (isset($trans_date_setting) and $trans_date_setting == "yes") { $trans_date_value = getCSetting("TRANSACTION_DATE"); $date_arr = explode("-", $trans_date_value); $deldate[0] = $date_arr[0]; $deldate[1] = $date_arr[1]; $deldate[2] = $date_arr[2]; } else { $deldate[0] = date("Y"); $deldate[1] = date("m"); $deldate[2] = date("d"); } } $details_begin = "\n\t\t<center>\n\t\t<h3>New Invoice</h3>\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t<input type='hidden' name='SCROLL' value='yes'>\n\t\t\t<input type='hidden' name='key' value='update'>\n\t\t\t<input type='hidden' name='invid' value='{$invid}'>\n\t\t\t<input type='hidden' name='stkerr' value='{$stkerr}'>\n\t\t<table " . TMPL_tblDflts . " width='95%'>\n\t\t \t<tr>\n\t\t \t\t<td valign='top' width='50%'>\n\t\t \t\t\t<div id='cust_selection'>"; if (empty($ajax_err) && (isset($cusnum) || AJAX)) { if (isset($cusnum)) { $OTS_OPT = onthespot_encode(SELF, "cust_selection", "deptid={$inv['deptid']}&letters={$letters}&cusnum={$cusnum}&invid={$invid}"); $custedit = "\n\t\t\t\t<td nowrap>\n\t\t\t\t\t<a href='javascript: popupSized(\"customers-new.php?cusnum={$cusnum}&onthespot={$OTS_OPT}\", \"edit_cust\", 700, 630);'>Edit Customer Details</a>\n\t\t\t\t</td>"; } else { $custedit = ""; } $optional_filter_setting = getCSetting("OPTIONAL_STOCK_FILTERS"); if (isset($optional_filter_setting) and $optional_filter_setting == "yes") { db_connect(); $catsql = "SELECT catid, cat, catcod FROM stockcat WHERE div = '" . USER_DIV . "' ORDER BY cat ASC"; $catRslt = db_exec($catsql); if (pg_numrows($catRslt) < 1) { $cat_drop = "<input type='hidden' name='filter_cat' value='0'>"; } else { $cat_drop = "<select name='filter_cat'>"; $cat_drop .= "<option value='0'>All Categories</option>"; while ($cat = pg_fetch_array($catRslt)) { if (isset($filter_cat) and $filter_cat == $cat['catid']) { $cat_drop .= "<option value='{$cat['catid']}' selected>({$cat['catcod']}) {$cat['cat']}</option>"; } else { $cat_drop .= "<option value='{$cat['catid']}'>({$cat['catcod']}) {$cat['cat']}</option>"; } } $cat_drop .= "</select>"; } # Select classification $classsql = "SELECT * FROM stockclass WHERE div = '" . USER_DIV . "' ORDER BY classname ASC"; $clasRslt = db_exec($classsql); if (pg_numrows($clasRslt) < 1) { $class_drop = "<input type='hidden' name='filter_class' value='0'>"; } else { $class_drop = "<select name='filter_class' style='width: 167'>"; $class_drop .= "<option value='0'>All Classifications</option>"; while ($clas = pg_fetch_array($clasRslt)) { if (isset($filter_class) and $filter_class == $clas['clasid']) { $class_drop .= "<option value='{$clas['clasid']}' selected>{$clas['classname']}</option>"; } else { $class_drop .= "<option value='{$clas['clasid']}'>{$clas['classname']}</option>"; } } $class_drop .= "</select>"; } $display_optional_filters = "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Category</td>\n\t\t\t\t\t<td>{$cat_drop}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Classification</td>\n\t\t\t\t\t<td>{$class_drop}</td>\n\t\t\t\t</tr>"; } db_conn("exten"); $sql = "SELECT whid, whname, whno FROM warehouses WHERE div = '" . USER_DIV . "' ORDER BY whname ASC"; $whRslt = db_exec($sql); if (pg_numrows($whRslt) < 1) { $store_drop = "<input type='hidden' name='filter_store' value='0'>"; } else { if (!isset($filter_store)) { # check if setting exists db_connect(); $sql = "SELECT value FROM set WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'"; $Rslt = db_exec($sql) or errDie("Unable to check database for existing settings."); if (pg_numrows($Rslt) > 0) { $set = pg_fetch_array($Rslt); $filter_store = $set['value']; } } $store_drop = "<select name='filter_store'>"; $store_drop .= "<option value='0'>All Stores</option>"; while ($wh = pg_fetch_array($whRslt)) { if ($wh['whid'] == $filter_store) { $store_drop .= "<option value='{$wh['whid']}' selected>({$wh['whno']}) {$wh['whname']}</option>"; } else { $store_drop .= "<option value='{$wh['whid']}'>({$wh['whno']}) {$wh['whname']}</option>"; } } $store_drop .= "</select>"; } $ajaxOut = "\n\t\t\t<input type='hidden' name='letters' value='{$letters}'>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'> Customer Details </th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Department</td>\n\t\t\t\t\t<td valign='center'>{$dept['deptname']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account No.</td>\n\t\t\t\t\t<td valign='center'>{$cust['accno']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer</td>\n\t\t\t\t\t<td valign='center'>{$customers}</td>\n\t\t\t\t\t{$custedit}\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Customer Branch</td>\n\t\t\t\t\t<td valign='center'>{$branchdrop}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Customer Address</td>\n\t\t\t\t\t<td valign='center'>" . nl2br($cust['addr1']) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Current Delivery Address</td>\n\t\t\t\t\t<td valign='center'>" . nl2br($cust_del_addr) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Delivery Address</td>\n\t\t\t\t\t<td valign='center'>\n\t\t\t\t\t\t<input type='button' onClick=\"\n\t\t\t\t\t\t\tvar windowReference;\n\n\t\t\t\t\t\t\tfunction openPopup() {\n\t\t\t\t\t\t\t\twindowReference = window.open('cust-credit-stockinv-deladdr.php?invid={$invid}','windowName','width=500,height=400,status=1');\n\t\t\t\t\t\t\t\tif (!windowReference.opener)\n\t\t\t\t\t\t\t\t\twindowReference.opener = self;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\topenPopup();\" value='Change Delivery Address'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer Order number</td>\n\t\t\t\t\t<td valign='center'><input type='text' size='10' name='cordno' value='{$inv['cordno']}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer VAT Number</td>\n\t\t\t\t\t<td>{$cust['vatnum']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Point of Sale</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Barcode</td>\n\t\t\t\t\t<td><input type='text' size='13' name='bar' value=''></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Print Delivery Note</td>\n\t\t\t\t\t<td><input type='checkbox' name='printdel' {$chp}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Using</td>\n\t\t\t\t\t<td>Stock Code<input type='radio' name='sel_frm' value='stkcod' onChange='javascript:document.form.submit();' {$sel_frm_cod}><br>Stock Description<input type='radio' name='sel_frm' value='stkdes' onChange='javascript:document.form.submit();' {$sel_frm_des}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Additional Filters</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Store</td>\n\t\t\t\t\t<td>{$store_drop}</td>\n\t\t\t\t</tr>\n\t\t\t\t{$display_optional_filters}\n\t\t\t\t<tr class='" . bg_class() . "' " . ass("Type the first letters of the stock code you are looking for.") . ">\n\t\t\t\t\t<td>Stock Filter</td>\n\t\t\t\t\t<td nowrap><input type='text' size='13' name='ria' value='{$ria}'> <input type='submit' value='Search'> <input type='submit' name='ria' value='Show All'></td>\n\t\t\t\t</tr>\n\t\t\t</table>"; } else { db_conn("exten"); $sql = "SELECT * FROM departments WHERE div = '" . USER_DIV . "' ORDER BY deptname ASC"; $deptRslt = db_exec($sql) or errDie("Unable to view customers"); if (pg_numrows($deptRslt) < 1) { return "<li class='err'>There are no Departments found in Cubit.</li>"; } else { $depts = "<select name='deptid' id='deptid'>"; $depts .= "<option value='0'>All Departments</option>"; while ($dept = pg_fetch_array($deptRslt)) { $depts .= "<option value='{$dept['deptid']}'>{$dept['deptname']}</option>"; } $depts .= "</select>"; } if (!isset($ajax_err)) { $ajax_err = ""; } $ajaxOut = "\n\t\t\t<script>\n\t\t\t\tfunction updateCustSelection() {\n\t\t\t\t\tdeptid = getObject('deptid').value;\n\t\t\t\t\tletters = getObject('letters').value;\n\t\t\t\t\tctyp = getObject('ctypintl').checked;\n\t\t\t\t\tif (ctyp) {\n\t\t\t\t\t\tdocument.location.href='intinvoice-new.php?' + 'letters=' + letters + '&deptid=' + deptid + '&ctyp=' + ctyp + '&invid={$invid}';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tajaxRequest('" . SELF . "', 'cust_selection', AJAX_SET, 'letters='+letters+'&deptid='+deptid+'&ctyp='+ctyp+'&invid={$invid}');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t</script>\n\t\t\t{$ajax_err}\n\t\t\t<form name='cusselfrm'>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Customer Selection</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select Department</td>\n\t\t\t\t\t<td valign='center'>{$depts}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>First Letters of customer</td>\n\t\t\t\t\t<td valign='center'><input type='text' size='5' id='letters' maxlength='5'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Customer is International</td>\n\t\t\t\t\t<td valign='center'><input type='checkbox' id='ctypintl'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><br /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td valign='center'><input type='button' value='Update »' onClick='updateCustSelection();'></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form>"; } $avcred = sprint($avcred); if (isset($addprodBtn) or isset($addnon) or isset($saveBtn) or isset($upBtn) or isset($ria)) { $jump_bot = "\n\t\t\t<script>\n\t\t\t\twindow.location.hash='bottom';\n\t\t\t</script>"; } else { $jump_bot = ""; } $details_end = "\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td valign='top' align='right' width='50%'>\n\t\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<th colspan='2'> Invoice Details </th>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Invoice No.</td>\n\t\t\t\t\t\t\t\t<td valign='center'>TI {$inv['invid']}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Proforma Inv No.</td>\n\t\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='docref' value='{$inv['docref']}'></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Sales Order No.</td>\n\t\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='ordno' value='{$inv['ordno']}'></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>VAT Inclusive</td>\n\t\t\t\t\t\t\t\t<td valign='center'>Yes <input type='radio' size='7' name='chrgvat' value='inc' {$chin}> No<input type='radio' size='7' name='chrgvat' value='exc' {$chex}></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Terms</td>\n\t\t\t\t\t\t\t\t<td valign='center'>{$termssel} Days</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Sales Person</td>\n\t\t\t\t\t\t\t\t{$sales}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Invoice Date</td>\n\t\t\t\t\t\t\t\t<td valign='center'>" . mkDateSelect("inv_date", $inv_date_year, $inv_date_month, $inv_date_day) . "</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Available Credit</td>\n\t\t\t\t\t\t\t\t<td>" . CUR . " {$avcred}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Trade Discount</td>\n\t\t\t\t\t\t\t\t<td valign='center'><input type='text' size='5' name='traddisc' value='{$inv['traddisc']}'>%</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Delivery Charge</td>\n\t\t\t\t\t\t\t\t<td valign='center'><input type='text' size='7' name='delchrg' value='{$inv['delchrg']}'>{$Vatcodes}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Delivery Date</td>\n\t\t\t\t\t\t\t\t<td valign='center'>" . mkDateSelect("del_date", $deldate[0], $deldate[1], $deldate[2]) . "</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t" . TBL_BR . "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='2'>{$products}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<th width='25%'>Quick Links</th>\n\t\t\t\t\t\t\t\t<th width='25%'>Comments</th>\n\t\t\t\t\t\t\t\t<td rowspan='5' valign='top' width='50%'>{$error}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td class='" . bg_class() . "'><a href='customers-new.php?re={$inv['invid']}'>New Customer</a></td>\n\t\t\t\t\t\t\t\t<td class='" . bg_class() . "' rowspan='5' align='center' valign='top'><textarea name='comm' rows='4' cols='20'>{$comm}</textarea></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td class='" . bg_class() . "'><a href='cust-credit-stockinv.php'>New Invoice</a></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><a href='invoice-view.php'>View Invoices</a></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><a href='settings/cust-credit-stockinv-newsetting.php?change=yes'>Change Invoice Complete Setting</a></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' valign='top'>\n\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='50%'>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>SUBTOTAL</td>\n\t\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " <input type='hidden' name='SUBTOT' value='{$SUBTOT}'>{$SUBTOT}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Trade Discount</td>\n\t\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$inv['discount']}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Delivery Charge</td>\n\t\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$inv['delivery']}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><b>VAT {$vat14}</b></td>\n\t\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$VAT}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<th>GRAND TOTAL</th>\n\t\t\t\t\t\t\t\t<td align='right' nowrap>" . CUR . " {$TOTAL}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align='right'><input name='addprodBtn' type='submit' value='Add Product'> | <input name='addnon' type='submit' value='Add Non stock Product'> | <input type='submit' name='saveBtn' value='Save'> </td>\n\t\t\t\t\t<td nowrap>| <input type='submit' name='upBtn' value='Update'>{$done}</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<a name='bottom'>\n\t\t\t</form>\n\t\t\t</center>\n\t\t\t{$jump_bot}"; if (!isset($reload)) { $reload = FALSE; $send_override = ""; } if ($reload) { $details_end .= "\n\t\t\t\t\t\t{$send_override}\n\t\t\t\t\t\t<script>\n\t\t\t\t\t\t\tonLoad=document.form.submit();\n\t\t\t\t\t\t</script>\n\t\t\t\t\t"; } if (AJAX) { return $ajaxOut; } else { return "{$details_begin}{$ajaxOut}{$details_end}"; } }