/** * returns general email settings, and if done does an r2sListSet and goes to email settings page * * @return array */ function qryEmailSettings() { $qry = new dbSelect("esettings", "cubit"); $qry->run(); $invalid = false; if ($qry->num_rows() <= 0) { $invalid = true; } else { $d = $qry->fetch_array(); $qry->free(); if ($d["smtp_host"] == "" || $d["fromname"] == "") { $invalid = true; } } if ($invalid) { r2sListSet("emailsettings"); header("Location: email-settings.php"); exit; } return $d; }
/** * locates a supplier by name, if not found creates and returns id * * @param string $name company name * @return int */ function locateSupplier($name) { $qry = new dbSelect("suppliers", "cubit", grp(m("cols", "supid"), m("where", "lower(supname)=lower('{$name}')"))); $qry->run(); if ($qry->num_rows() > 0) { $id = $qry->fetch_result(); } else { // insert into new supps $id = -1; } $qry->free(); return $id; }
function enter($err = "") { extract($_REQUEST); $fields = grp(m("deptid", 0), m("accno", false), m("surname", ""), m("title", ""), m("location", ""), m("fcid", ""), m("category", 0), m("class", 0), m("init", ""), m("sales_rep", 0), m("paddr1", ""), m("addr1", ""), m("del_addr1", ""), m("comments", ""), m("vatnum", ""), m("contname", ""), m("bustel", ""), m("tel", ""), m("cellno", ""), m("fax", ""), m("email", ""), m("url", ""), m("pricelist", 0), m("traddisc", 0), m("setdisc", 0), m("chrgint", 0), m("overdue", 0), m("intrate", 0), m("o_year", date("Y")), m("o_month", date("m")), m("o_day", date("d")), m("credterm", 0), m("credlimit", ""), m("lead_source", 0), m("bankname", ""), m("branname", ""), m("brancode", ""), m("bankaccname", ""), m("bankaccno", ""), m("bankacctype", ""), m("team_id", 0), m("registration", "")); if (isset($cusnum)) { if ($cusnum == "-S") { return "<li class='err'>Invalid Customer</li><br><input type='button' value='[X] Close' onClick=\"window.close();\">"; } $qry = new dbSelect("customers", "cubit", grp(m("where", "cusnum='{$cusnum}'"))); $qry->run(); if ($qry->num_rows() <= 0) { $OUT = "<li class='err'>Customer not found.</li>"; return $OUT; } $c = $qry->fetch_array(); $qry->free(); /* split the date into the fields */ list($c["o_year"], $c["o_month"], $c["o_day"]) = explode("-", $c["odate"]); foreach ($fields as $k => $v) { if (isset($c[$k])) { $fields[$k] = $c[$k]; } } $cusid = "<input type='hidden' name='cusnum' value='{$cusnum}' />"; } else { $cusid = ""; } extract($fields, EXTR_SKIP); /* get next available account number */ if ($accno === false) { $lastid = pglib_lastid("cubit.customers", "cusnum"); $sql = "SELECT accno FROM cubit.customers WHERE cusnum = '{$lastid}' AND div = '" . USER_DIV . "'"; $accRslt = db_exec($sql); if (pg_numrows($accRslt) < 1) { do { $lastid--; # get last account number $sql = "SELECT accno FROM cubit.customers WHERE cusnum = '{$lastid}' AND div = '" . USER_DIV . "'"; $accRslt = db_exec($sql); if (pg_numrows($accRslt) < 1) { $accno = ""; $naccno = ""; } else { $acc = pg_fetch_array($accRslt); $accno = $acc['accno']; } } while (strlen($accno) < 1 && $lastid > 1); } else { $acc = pg_fetch_array($accRslt); $accno = $acc['accno']; } if (strlen($accno) > 0) { $num = preg_replace("/[^\\d]+/", "", $accno); $num++; $chars = preg_replace("/[\\d]/", "", $accno); $naccno = $chars . $num; } else { $naccno = 1; } $accno = $naccno; } /* customer categories */ $qry = qryCategory(); $cats = db_mksel($qry, "category", $category, "#catid", "#category"); /* customer class */ $qry = qryClass(); $classlist = db_mksel($qry, "class", $class, "#clasid", "#classname"); /* pricelists */ $qry = qryPricelist(); $pricelists = db_mksel($qry, "pricelist", $pricelist, "#listid", "#listname"); /* customer departments */ $qry = qryDepartment(); $depts = db_mksel($qry, "deptid", $deptid, "#deptid", "#deptname"); /* customer title */ $get_titles = "SELECT title FROM titles ORDER BY title"; $run_titles = db_exec($get_titles) or errDie("Unable to get title information."); if (pg_numrows($run_titles) < 1) { $titles = array("Mr" => "Mr", "Mrs" => "Mrs", "Miss" => "Miss"); } else { $titles = array(); while ($tarr = pg_fetch_array($run_titles)) { $titles[$tarr['title']] = $tarr['title']; } } $titles = extlib_cpsel("title", $titles, $title); /* credit terms */ $qry = new dbSelect("ct", "exten", grp(m("where", "div='" . USER_DIV . "'"))); $qry->run(); while ($cd = $qry->fetch_array()) { $days[$cd['days']] = $cd['days']; } $credterms = extlib_cpsel("credterm", $days, $credterm); // unset so we can use same array unset($days); /* overdue periods */ $qry = new dbSelect("od", "exten", grp(m("where", "div='" . USER_DIV . "'"))); $qry->run(); while ($cd = $qry->fetch_array()) { $days[$cd['days']] = $cd['days']; } $overdues = extlib_cpsel("overdue", $days, $overdue); /* customer is local/international */ $locs = grp(m("loc", "Local"), m("int", "International")); $locsel = extlib_cpsel("location", $locs, $location); /* currency */ $qry = qryCurrency(); $currsel = db_mksel($qry, "fcid", $fcid, "#fcid", "#descrip"); /* lead sources */ $select_source = extlib_cpsel("lead_source", crm_get_leadsrc(-1), $lead_source); /* something from crm */ if (isset($_GET["crm"])) { $ex = "<input type='hidden' name='crm' value='' />"; } else { $ex = ""; } /* sales rep selection */ $qry = qrySalesPerson(); $sales_reps = db_mksel($qry, "sales_rep", $sales_rep, "#salespid", "#salesp", "0:None"); if (!isset($re)) { $re = "not"; } else { $re = remval($re); } if (isset($cusnum)) { $bran = "\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Branches</td>\n\t\t\t<td><input type='button' onClick=\"window.open('cust-branch-add.php?cusnum={$cusnum}','','width=380,height=300,status=1')\" value='Add Branch'><input type=button onClick=\"window.open('cust-branch-view.php?cusnum={$cusnum}','','width=500,height=400,status=1')\" value='View Branch'></td>\n\t\t</tr>"; } else { $bran = ""; } // Retrieve teams $sql = "SELECT * FROM crm.teams ORDER BY name ASC"; $team_rslt = db_exec($sql) or errDie("Unable to retrieve teams."); $team_sel = "<select name='team_id'>"; $team_sel .= "<option value='0'>[None]</option>"; while ($team_data = pg_fetch_array($team_rslt)) { if ($team_id == $team_data["id"]) { $sel = "selected"; } else { $sel = ""; } $team_sel .= "<option value='{$team_data['id']}' {$sel}>{$team_data['name']}</option>"; } $team_sel .= "</select>"; // Layout $OUT = "\n\t<form action='" . SELF . "' method='post'>\n\t\t{$err}\n\t\t<input type='hidden' name='key' value='confirm' />\n\t\t<input type='hidden' name='re' value='{$re}' />\n\t\t{$ex}\n\t\t{$cusid}\n\t\t" . onthespot_passon() . "\n\t<table cellpadding='0' cellspacing='0'>\n\t\t<tr>\n\t\t\t<th colspan='2'>Add Customer : Customer Details</th>\n\t\t</tr>\n\t\t<tr valign='top'>\n\t\t\t<td>\n\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Department</td>\n\t\t\t\t\t<td>{$depts}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Acc No</td>\n\t\t\t\t\t<td><input type='text' size='20' name='accno' value='{$accno}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Company/Name</td>\n\t\t\t\t\t<td><input type='text' size='20' name='surname' value='{$surname}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Registration/ID</td>\n\t\t\t\t\t<td><input type='text' size='20' name='registration' value='{$registration}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Title {$titles}</td>\n\t\t\t\t\t<td>Initials <input type='text' size='15' name='init' value='{$init}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Type</td>\n\t\t\t\t\t<td>{$locsel}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Currency</td>\n\t\t\t\t\t<td>{$currsel}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "' " . ass("Categories are used to group customers. For example: PTA,JHB,CT") . ">\n\t\t\t\t\t<td>" . REQ . "Category</td>\n\t\t\t\t\t<td>{$cats}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "' " . ass("Classifications are used to group customers. For example: Wholesale,Retail") . ">\n\t\t\t\t\t<td>" . REQ . "Classification</td>\n\t\t\t\t\t<td>{$classlist}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Link to Sales rep</td>\n\t\t\t\t\t<td>{$sales_reps}</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'>" . REQ . "Postal Address</td>\n\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='paddr1'>{$paddr1}</textarea></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'>\n\t\t\t\t\t\t" . REQ . "Physical Address<br>\n\t\t\t\t\t\t<font size='-2'>\n\t\t\t\t\t\t\t<input style='width: 11px; height: 11px;' type='checkbox' name='addr_same' " . (isset($addr_same) ? "checked='t'" : "") . " />\n\t\t\t\t\t\t\tSame As Postal Address\n\t\t\t\t\t\t</font>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='addr1'>{$addr1}</textarea></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'><textarea rows='4' cols='19' name='del_addr1'>{$del_addr1}</textarea></td>\n\t\t\t\t</tr>\n\t\t\t\t{$bran}\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Team Permissions</td>\n\t\t\t\t\t<td>{$team_sel}</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'>Comments</td>\n\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='comments'>{$comments}</textarea></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "VAT Number</td>\n\t\t\t\t\t<td><input type='text' size='21' name='vatnum' value='{$vatnum}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Business Tel.</td>\n\t\t\t\t\t<td><input type='text' size='21' name='bustel' value='{$bustel}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Contact Name</td>\n\t\t\t\t\t<td><input type='text' size='21' name='contname' value='{$contname}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Home Tel.</td>\n\t\t\t\t\t<td><input type='text' size='21' name='tel' value='{$tel}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Cell No.</td>\n\t\t\t\t\t<td><input type='text' size='21' name='cellno' value='{$cellno}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Fax No.</td>\n\t\t\t\t\t<td><input type='text' size='21' name='fax' value='{$fax}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>E-mail</td>\n\t\t\t\t\t<td><input type='text' size='21' name='email' value='{$email}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Web Address</td>\n\t\t\t\t\t<td>http://<input type='text' size='30' name='url' value='{$url}' /></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "' " . ass("When invoicing prices comes from the pricelist. Add more at stock settings.") . ">\n\t\t\t\t\t<td>" . REQ . "Price List</td>\n\t\t\t\t\t<td>{$pricelists}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td " . ass("This is the default discount on invoices, but can be changed per invoice") . ">Trade Discount <input type='text' size='6' name='traddisc' value='{$traddisc}' />%</td>\n\t\t\t\t\t<td>Settlement Discount <input type='text' size='7' name='setdisc' value='{$setdisc}' />%</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>" . REQ . "Charge Interest : Yes <input type='radio' name='chrgint' value='yes' " . ($chrgint == "yes" ? "checked='t'" : "") . " /> No<input type='radio' name='chrgint' value='no' " . ($chrgint != "yes" ? "checked='t'" : "") . " /></td>\n\t\t\t\t\t<td " . ass("Depending on interest settings, invoices older than this will get interest.") . ">Overdue {$overdues}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "' " . ass("Depending on interest settings, this is the interest this client will be charged.") . ">\n\t\t\t\t\t<td>Interest Rate</td>\n\t\t\t\t\t<td><input type='text' size='7' name='intrate' value='{$intrate}' />%</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account Open Date</td>\n\t\t\t\t\t<td>" . mkDateSelect("o", $o_year, $o_month, $o_day) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Credit Term {$credterms}</td>\n\t\t\t\t\t<td>Credit Limit: 0<input type='hidden' name='credlimit' value='0'/></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Lead Source</td>\n\t\t\t\t\t<td>{$select_source}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><Td><br></td></tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<th colspan='2'> Bank Details</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Bank </td>\n\t\t\t\t\t<td><input type='text' size='20' name='bankname' value='{$bankname}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Branch</td>\n\t\t\t\t\t<td><input type='text' size='20' name='branname' value='{$branname}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Branch Code</td>\n\t\t\t\t\t<td><input type='text' size='20' name='brancode' value='{$brancode}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account Name</td>\n\t\t\t\t\t<td><input type='text' size='20' name='bankaccname' value='{$bankaccname}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account Number</td>\n\t\t\t\t\t<td><input type='text' size='20' name='bankaccno' value='{$bankaccno}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account Type</td>\n\t\t\t\t\t<td><input type='text' size='20' name='bankacctype' value='{$bankacctype}'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='2' align='right'><input type='submit' value='Confirm »' /></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align='center'>\n\t\t\t\t</table>" . mkQuickLinks(ql("customers-view.php", "View Customers")); return $OUT; }
function enter($err = "") { extract($_REQUEST); $fields = grp(m("deptid", 0), m("accno", false), m("surname", ""), m("title", ""), m("location", ""), m("fcid", ""), m("category", 0), m("class", 0), m("init", ""), m("sales_rep", 0), m("paddr1", ""), m("addr1", ""), m("del_addr1", ""), m("comments", ""), m("vatnum", ""), m("contname", ""), m("bustel", ""), m("tel", ""), m("cellno", ""), m("fax", ""), m("email", ""), m("url", ""), m("pricelist", 0), m("traddisc", 0), m("setdisc", 0), m("setdays", 1), m("chrgint", 0), m("overdue", 0), m("intrate", 0), m("o_year", date("Y")), m("o_month", date("m")), m("o_day", date("d")), m("credterm", 0), m("credlimit", ""), m("lead_source", 0), m("bankname", ""), m("branname", ""), m("brancode", ""), m("bankaccname", ""), m("bankaccno", ""), m("bankacctype", ""), m("team_id", 0), m("registration", ""), m("bankacct", ""), m("bankid", 0), m("blocked", "no")); if (isset($cusnum)) { if ($cusnum == "-S") { return "<li class='err'>Invalid Customer</li><br><input type='button' value='[X] Close' onClick=\"window.close();\">"; } $qry = new dbSelect("customers", "cubit", grp(m("where", "cusnum='{$cusnum}'"))); $qry->run(); if ($qry->num_rows() <= 0) { $OUT = "<li class='err'>Customer not found.</li>"; return $OUT; } $c = $qry->fetch_array(); $qry->free(); /* split the date into the fields */ list($c["o_year"], $c["o_month"], $c["o_day"]) = explode("-", $c["odate"]); foreach ($fields as $k => $v) { if (isset($c[$k])) { $fields[$k] = $c[$k]; } } $cusid = "<input type='hidden' name='cusnum' value='{$cusnum}' />"; } else { $cusid = ""; } extract($fields, EXTR_SKIP); /* get next available account number */ if ($accno === false) { $lastid = pglib_lastid("cubit.customers", "cusnum"); $sql = "SELECT accno FROM cubit.customers WHERE cusnum = '{$lastid}' AND div = '" . USER_DIV . "'"; $accRslt = db_exec($sql); if (pg_numrows($accRslt) < 1) { do { $lastid--; # get last account number $sql = "SELECT accno FROM cubit.customers WHERE cusnum = '{$lastid}' AND div = '" . USER_DIV . "'"; $accRslt = db_exec($sql); if (pg_numrows($accRslt) < 1) { $accno = ""; $naccno = ""; } else { $acc = pg_fetch_array($accRslt); $accno = $acc['accno']; } } while (strlen($accno) < 1 && $lastid > 1); } else { $acc = pg_fetch_array($accRslt); $accno = $acc['accno']; } if (strlen($accno) > 0) { $num = preg_replace("/[^\\d]+/", "", $accno); $num++; $chars = preg_replace("/[\\d]/", "", $accno); $naccno = $chars . $num; } else { $naccno = 1; } $accno = $naccno; } /* customer categories */ $qry = qryCategory(); $cats = db_mksel($qry, "category", $category, "#catid", "#category"); /* customer class */ $qry = qryClass(); $classlist = db_mksel($qry, "class", $class, "#clasid", "#classname"); /* pricelists */ $qry = qryPricelist(); $pricelists = db_mksel($qry, "pricelist", $pricelist, "#listid", "#listname"); /* customer departments */ $qry = qryDepartment(); $depts = db_mksel($qry, "deptid", $deptid, "#deptid", "#deptname"); /* customer title */ $get_titles = "SELECT title FROM titles ORDER BY title"; $run_titles = db_exec($get_titles) or errDie("Unable to get title information."); if (pg_numrows($run_titles) < 1) { $titles = array("Mr" => "Mr", "Mrs" => "Mrs", "Miss" => "Miss"); } else { $titles = array(); while ($tarr = pg_fetch_array($run_titles)) { $titles[$tarr['title']] = $tarr['title']; } } $titles = extlib_cpsel("title", $titles, $title); /* credit terms */ $qry = new dbSelect("ct", "exten", grp(m("where", "div='" . USER_DIV . "'"))); $qry->run(); while ($cd = $qry->fetch_array()) { $days[$cd['days']] = $cd['days']; } $cred_days = array("0" => "0", "30" => "30", "60" => "60"); $credterms = extlib_cpsel("credterm", $cred_days, $credterm); // unset so we can use same array unset($days); /* overdue periods */ // $qry = new dbSelect("od", "exten", grp( // m("where", "div='".USER_DIV."'") // )); // $qry->run(); // while ($cd = $qry->fetch_array()) { // $days[$cd['days']] = $cd['days']; // } // $overdues = extlib_cpsel("overdue", $days, $overdue); /* customer is local/international */ $locs = grp(m("loc", "Local"), m("int", "International")); $locsel = extlib_cpsel("location", $locs, $location); /* currency */ $qry = qryCurrency(); $currsel = db_mksel($qry, "fcid", $fcid, "#fcid", "#descrip"); /* lead sources */ $select_source = extlib_cpsel("lead_source", crm_get_leadsrc(-1), $lead_source); /* something from crm */ if (isset($_GET["crm"])) { $ex = "<input type='hidden' name='crm' value='' />"; } else { $ex = ""; } /* sales rep selection */ $qry = qrySalesPerson(); $sales_reps = db_mksel($qry, "sales_rep", $sales_rep, "#salespid", "#salesp", "0:None"); if (!isset($re)) { $re = "not"; } else { $re = remval($re); } if (isset($cusnum)) { $bran = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Branches</td>\n\t\t\t\t<td><input type='button' onClick=\"window.open('cust-branch-add.php?cusnum={$cusnum}','','width=380,height=300,status=1')\" value='Add Branch'><input type=button onClick=\"window.open('cust-branch-view.php?cusnum={$cusnum}','','width=500,height=400,status=1')\" value='View Branch'></td>\n\t\t\t</tr>"; } else { $bran = ""; } // Retrieve teams $sql = "SELECT * FROM crm.teams ORDER BY name ASC"; $team_rslt = db_exec($sql) or errDie("Unable to retrieve teams."); $team_sel = "<select name='team_id'>"; $team_sel .= "<option value='0'>[None]</option>"; while ($team_data = pg_fetch_array($team_rslt)) { if ($team_id == $team_data["id"]) { $sel = "selected"; } else { $sel = ""; } $team_sel .= "<option value='{$team_data['id']}' {$sel}>{$team_data['name']}</option>"; } $team_sel .= "</select>"; $get_accts = "SELECT * FROM bankacct ORDER BY accname"; $run_accts = db_exec($get_accts) or errDie("Unable to get bank account information."); if (pg_numrows($run_accts) < 1) { $bankacct_drop = ""; } else { $bankacct_drop = "<select name='bankid'>"; while ($barr = pg_fetch_array($run_accts)) { if ($bankid == $barr['bankid']) { $bankacct_drop .= "<option value='{$barr['bankid']}' selected>({$barr['acctype']}) {$barr['accname']}</option>"; } else { $bankacct_drop .= "<option value='{$barr['bankid']}'>({$barr['acctype']}) {$barr['accname']}</option>"; } } $bankacct_drop .= "</select>"; } $setdayssel1 = ""; $setdayssel2 = ""; $setdayssel3 = ""; $setdayssel4 = ""; $setdayssel5 = ""; if (isset($setdays) and $setdays == "0") { $setdayssel1 = "selected"; } if (isset($setdays) and $setdays == "1") { $setdayssel2 = "selected"; } if (isset($setdays) and $setdays == "7") { $setdayssel3 = "selected"; } if (isset($setdays) and $setdays == "15") { $setdayssel4 = "selected"; } if (isset($setdays) and $setdays == "25") { $setdayssel5 = "selected"; } // <option $setdayssel1 value='0'>Last Day Of The Month</option> $setdays_drop = "\n\t\t<select name='setdays'>\n\t\t\t<option {$setdayssel2} value='1'>1st Day Of The Month</option>\n\t\t\t<option {$setdayssel3} value='7'>7th Of The Month</option>\n\t\t\t<option {$setdayssel4} value='15'>15th Of The Month</option>\n\t\t\t<option {$setdayssel5} value='25'>25th Of The Month</option>\n\t\t</select>"; //Overdue $overdues $display_piclist = ""; $display_iframe = ""; #check if this cust has any pics ... if (isset($cusnum) and strlen($cusnum) > 0) { #editing customer ... show frame if we have pics $get_pics = "SELECT * FROM display_images WHERE type = 'customer' AND ident_id = '{$cusnum}' LIMIT 1"; $run_pics = db_exec($get_pics) or errDie("Unable to get customer images information."); if (pg_numrows($run_pics) < 1) { #no pics for this customer $display_iframe = ""; } else { #compile listing for customer $get_piclist = "SELECT * FROM display_images WHERE type = 'customer' AND ident_id = '{$cusnum}'"; $run_piclist = db_exec($get_piclist) or errDie("Unable to get customer images information."); if (pg_numrows($run_piclist) < 1) { #wth .. pic went missing somewhere ... #so nothing } else { $display_piclist = "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='2'>\n\t\t\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<th>Picture Name</th>\n\t\t\t\t\t\t\t\t\t<th>View</th>\n\t\t\t\t\t\t\t\t\t<th>Remove</th>\n\t\t\t\t\t\t\t\t</tr>"; while ($arr = pg_fetch_array($run_piclist)) { $display_piclist .= "\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td>{$arr['image_name']}</td>\n\t\t\t\t\t\t\t\t\t<td><a target='iframe1' href='view_image.php?picid={$arr['id']}'>View</a></td>\n\t\t\t\t\t\t\t\t\t<td><input type='checkbox' name='rempicid[{$arr['id']}]' value='yes'></td>\n\t\t\t\t\t\t\t\t</tr>"; #at least 1 picture for this customer $display_iframe = "<tr><td colspan='2'><iframe name='iframe1' width='200' height='260' scrolling='false' marginwidth='0' marginheight='0' frameborder='0' src='view_image.php?picid={$arr['id']}'></iframe></td></tr>"; } $display_piclist .= "\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; } } } $show_back_button = ""; $show_next_button = ""; $showbuttons = ""; if (isset($cusnum) and strlen($cusnum) > 0 and $cusnum != 0) { db_connect(); #get 1 lower cusnum $get_prev = "SELECT cusnum FROM customers WHERE cusnum < '{$cusnum}' ORDER BY cusnum DESC LIMIT 1"; $run_prev = db_exec($get_prev) or errDie("Unable to get previous customer information."); if (pg_numrows($run_prev) > 0) { $back_cusnum = pg_fetch_result($run_prev, 0, 0); $show_back_button = "<input type='button' onClick=\"document.location='customers-new.php?cusnum={$back_cusnum}';\" value='View Previous Customer'>"; } $get_next = "SELECT cusnum FROM customers WHERE cusnum > '{$cusnum}' ORDER BY cusnum ASC LIMIT 1"; $run_next = db_exec($get_next) or errDie("Unable to get next customer information."); if (pg_numrows($run_next) > 0) { $next_cusnum = pg_fetch_result($run_next, 0, 0); $show_next_button = "<input type='button' onClick=\"document.location='customers-new.php?cusnum={$next_cusnum}';\" value='View Next Customer'>"; } $showbuttons = "{$show_back_button} {$show_next_button} <br><br>"; $showcontact = "<input type='button' onClick=\"popupSized('conper-add.php?type=cust&id={$cusnum}','Add Additional Contact','880','580')\" value='Add Additional Contact'>"; } //http://127.0.0.1/cubit3.33/conper-add.php?type=cust&id=2 // Layout $OUT = "\n\t\t{$showbuttons}\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t{$err}\n\t\t\t<input type='hidden' name='key' value='confirm' />\n\t\t\t<input type='hidden' name='re' value='{$re}' />\n\t\t\t<input type='hidden' name='blocked' value='{$blocked}' />\n\t\t\t{$ex}\n\t\t\t{$cusid}\n\t\t\t" . onthespot_passon() . "\n\t\t<table cellpadding='0' cellspacing='0'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>Add Customer : Customer Details</th>\n\t\t\t</tr>\n\t\t\t<tr valign='top'>\n\t\t\t\t<td>\n\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>" . REQ . "Department</td>\n\t\t\t\t\t\t<td>{$depts}</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>" . REQ . "Acc No</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='accno' value='{$accno}' /></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>" . REQ . "Company/Name</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='surname' value='{$surname}' /></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>" . REQ . "Registration/ID</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='registration' value='{$registration}'></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>" . REQ . "Title {$titles}</td>\n\t\t\t\t\t\t<td>Initials <input type='text' size='15' name='init' value='{$init}' /></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>" . REQ . "Type</td>\n\t\t\t\t\t\t<td>{$locsel}</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>" . REQ . "Currency</td>\n\t\t\t\t\t\t<td>{$currsel}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "' " . ass("Categories are used to group customers. For example: PTA,JHB,CT") . ">\n\t\t\t\t\t\t<td>" . REQ . "Category</td>\n\t\t\t\t\t\t<td>{$cats}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "' " . ass("Classifications are used to group customers. For example: Wholesale,Retail") . ">\n\t\t\t\t\t\t<td>" . REQ . "Classification</td>\n\t\t\t\t\t\t<td>{$classlist}</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>Link to Sales rep</td>\n\t\t\t\t\t\t<td>{$sales_reps}</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 valign='top'>" . REQ . " Postal Address</td>\n\t\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='paddr1'>{$paddr1}</textarea></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 valign='top'>\n\t\t\t\t\t\t\t" . REQ . " Physical Address<br>\n\t\t\t\t\t\t\t<font size='-2'>\n\t\t\t\t\t\t\t\t<input style='width: 11px; height: 11px;' type='checkbox' name='addr_same' " . (isset($addr_same) ? "checked='t'" : "") . " />\n\t\t\t\t\t\t\t\tSame As Postal Address\n\t\t\t\t\t\t\t</font>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='addr1'>{$addr1}</textarea></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 valign='top'>Delivery Address</td>\n\t\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='del_addr1'>{$del_addr1}</textarea></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t{$bran}\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Team Permissions</td>\n\t\t\t\t\t\t<td>{$team_sel}</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 valign='top'>Comments</td>\n\t\t\t\t\t\t<td valign='center'><textarea rows='4' cols='19' name='comments'>{$comments}</textarea></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<th colspan='2'> Bank 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>Bank </td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='bankname' value='{$bankname}'></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>Branch</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='branname' value='{$branname}'></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>Branch Code</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='brancode' value='{$brancode}'></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>Account Name</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='bankaccname' value='{$bankaccname}'></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>Account Number</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='bankaccno' value='{$bankaccno}'></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>Account Type</td>\n\t\t\t\t\t\t<td><input type='text' size='20' name='bankacctype' value='{$bankacctype}'></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>Bank Account To Use</td>\n\t\t\t\t\t\t<td>{$bankacct_drop}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>" . REQ . "VAT Number</td>\n\t\t\t\t\t\t<td><input type='text' size='21' name='vatnum' value='{$vatnum}' /></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>" . REQ . "Business Tel.</td>\n\t\t\t\t\t\t<td><input type='text' size='21' name='bustel' value='{$bustel}' /></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>Contact Name</td>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type='text' size='21' name='contname' value='{$contname}' />\n\t\t\t\t\t\t\t{$showcontact}\n\t\t\t\t\t\t</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>Home Tel.</td>\n\t\t\t\t\t\t<td><input type='text' size='21' name='tel' value='{$tel}' /></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>Cell No.</td>\n\t\t\t\t\t\t<td><input type='text' size='21' name='cellno' value='{$cellno}' /></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>Fax No.</td>\n\t\t\t\t\t\t<td><input type='text' size='21' name='fax' value='{$fax}' /></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>E-mail</td>\n\t\t\t\t\t\t<td><input type='text' size='21' name='email' value='{$email}' /></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>Web Address</td>\n\t\t\t\t\t\t<td>http://<input type='text' size='30' name='url' value='{$url}' /></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "' " . ass("When invoicing prices comes from the pricelist. Add more at stock settings.") . ">\n\t\t\t\t\t\t<td>" . REQ . "Price List</td>\n\t\t\t\t\t\t<td>{$pricelists}</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 " . ass("This is the default discount on invoices, but can be changed per invoice") . ">Trade Discount <input type='text' size='6' name='traddisc' value='{$traddisc}' />%</td>\n\t\t\t\t\t\t<td>Settlement Discount <input type='text' size='7' name='setdisc' value='{$setdisc}' />%</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>" . REQ . "Charge Interest : Yes <input type='radio' name='chrgint' value='yes' " . ($chrgint == "yes" ? "checked='t'" : "") . " /> No<input type='radio' name='chrgint' value='no' " . ($chrgint != "yes" ? "checked='t'" : "") . " /></td>\n\t\t\t\t\t\t<td>Statement Day {$setdays_drop}</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 " . ass("Depending on interest settings, invoices older than this will get interest.") . ">Interest Rate <input type='text' size='7' name='intrate' value='{$intrate}' />%</td>\n\t\t\t\t\t\t<td></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>Account Open Date</td>\n\t\t\t\t\t\t<td>" . mkDateSelect("o", $o_year, $o_month, $o_day) . "</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>Default Credit Term {$credterms}</td>\n\t\t\t\t\t\t<td>Credit Limit <input type='text' size='7' name='credlimit' value='{$credlimit}'/></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>Lead Source</td>\n\t\t\t\t\t\t<td>{$select_source}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t{$display_iframe}\n\t\t\t\t\t{$display_piclist}\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='2' align='right'><input type='submit' value='Confirm »' /></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t</form>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td align='center'>\n\t\t\t\t\t</table>" . mkQuickLinks(ql("customers-view.php", "View Customers")); return $OUT; }
/** * checks whether supplier is transheks configured * * @param int $suppid * @return bool */ function trhSupplierEnabled($suppid) { $qry = new dbSelect("config", "trh", grp(m("where", "value!='' AND (name='SMTP_SERVER' OR name='POP3_SERVER')"))); $qry->run(); $ret = $qry->num_rows() > 0; $qry->free(); return $ret; }
/** * handles a new request * * @param string $key * @param clsMailMsg $oMSG * @param array $config * @return bool */ function request_new($key, $oMSG, $config) { if (($stds = msg_std($oMSG)) === false) { return false; } list($compname, $ipaddr, $bustel, $fromwho, $email) = $stds; /* locate customer/supplier */ if ($fromwho == "supp") { $suppid = locateSupplier($compname); $custid = 0; } else { // $fromwho == "cust" $custid = locateCustomer($compname); $suppid = 0; } print "name: {$compname}\n"; print "ipaddr: {$ipaddr}\n"; print "bustel: {$bustel}\n"; print "fromwho: {$fromwho}\n"; print "custid: {$custid}\n"; print "suppid: {$suppid}\n"; /* check if company name and key is in list */ $qry = new dbSelect("keys", "trh", grp(m("cols", "1"), m("where", "{$fromwho}id='" . ${"{$fromwho}id"} . "' AND (key).send_key='{$key}'"))); $qry->run(); if ($qry->num_rows() > 0) { print "---> KEY EXISTS, ignoring\n"; return false; } $qry->free(); print "from email: {$email}\n"; /* generate a key for receiving for client */ $newkey = genkey(); /* add new key to system */ $cols = grp(m("userid", $config["MANAGEUSER"]), m("introtime", raw("CURRENT_TIMESTAMP")), m("introip", $ipaddr), m("email", $email), m("compname", $compname), m("bustel", $bustel), m("custid", $custid), m("suppid", $suppid), m("key", dbrow("0.0.0.0/0", $key, $newkey))); $upd = new dbUpdate("keys", "trh", $cols); $upd->run(DB_INSERT); $upd->free(); if ($custid == -1 && $suppid == -1) { $desc = $fromwho == "supp" ? "supplier" : "customer"; $userinfo = qryUsers($config["MANAGEUSER"]); msgSend($userinfo["username"], "Unknown {$desc} requested Transheks communication. \n\t\t\tClick <a target='mainframe' href=\"../transheks/commapprove.php\">here</a> to view."); return false; } else { /* send response */ return send_trhmsg($fromwho, ${"{$fromwho}id"}, $email, "rspkey", "{$newkey}", $config); } }