/** * returns the standard variables from message * * @param $oMSG * @return array */ function msg_std($oMSG) { /* get the company name */ if (($compname = getfrommmsg(REGEX_COMPNAME, $oMSG)) === false) { print "msgstd err: company name\n"; return false; } /* get the intro ip name */ if (($ipaddr = getfrommmsg(REGEX_IPADDR, $oMSG)) === false) { print "msgstd err: ip address\n"; return false; } /* get the telephone number */ if (($bustel = getfrommmsg(REGEX_TELEPHONE, $oMSG)) === false) { print "msgstd err: business telephone\n"; return false; } /* get from who (supp/cust) request came */ if (($fromwho = getfrommmsg(REGEX_FROMWHO, $oMSG)) === false) { print "msgstd err: from who\n"; return false; } /* get from email address */ if (($email = getfrommmsg(REGEX_FROMADDR, $oMSG, "From")) === false) { print "msgstd err: email\n"; return false; } return array($compname, $ipaddr, $bustel, $fromwho, $email); }
/** * handles a new purchase response * * @param string $key * @param clsMailMsg $oMSG * @param array $config * @return bool */ function response_order($key, $oMSG, $config) { if (($stds = msg_std($oMSG)) === false) { return false; } list($compname, $ipaddr, $bustel, $fromwho, $email) = $stds; /* other side key */ if (($yourkey = getfrommmsg(REGEX_YOURKEY, $oMSG)) === false) { return false; } /* purchase id in my database */ if (($purid = getfrommmsg(REGEX_PURID, $oMSG)) === false) { return false; } /* purchase accepted/invoices/denied */ if (($purstatus = getfrommmsg(REGEX_PURSTATUS, $oMSG)) === false) { return false; } /* validate keys */ if (($keyinfo = trhKeyPair($key, $yourkey)) === false) { return false; } $userinfo = qryUsers($keyinfo["userid"]); require_lib("validate"); $v = new validate(); if (!$v->isOk($purid, "num", 1, 20, "")) { return false; } $sql = "SELECT * FROM cubit.purchases WHERE purid = '{$purid}'"; if (!($purRslt = db_exec($sql))) { return false; } if (pg_num_rows($purRslt) < 1) { return false; } $pur = pg_fetch_array($purRslt); if ($purstatus == "d") { print "Denying purchase: {$purid}\n"; if ($pur['received'] == "y") { return false; } $sql = "SELECT * FROM cubit.pur_items WHERE purid = '{$purid}'"; if (!($stktRslt = db_exec($sql))) { return false; } while ($stkt = pg_fetch_array($stktRslt)) { print "\tRemoving Item: {$stkt['stkid']}\n"; $sql = "UPDATE cubit.stock SET ordered = (ordered - '{$stkt['qty']}') WHERE stkid = '{$stkt['stkid']}'"; if (!db_exec($sql)) { return false; } $sql = "INSERT INTO cubit.pur_canc_items (purid, whid, stkid, qty, ddate, div, qpack, upack, ppack, svat, rqty, tqty, unitcost, amt, iqty, vatcode, description, account)\n\t\t\t\t\tVALUES ('{$stkt['purid']}', '{$stkt['whid']}', '{$stkt['stkid']}', '{$stkt['qty']}', '{$stkt['ddate']}', '{$stkt['div']}', '{$stkt['qpack']}', '{$stkt['upack']}', '{$stkt['ppack']}', '{$stkt['svat']}', '{$stkt['rqty']}', '{$stkt['tqty']}', '{$stkt['unitcost']}', '{$stkt['amt']}', '{$stkt['iqty']}', '{$stkt['vatcode']}', '{$stkt['description']}', '{$stkt['account']}')"; if (!db_exec($sql)) { return false; } } $sql = "DELETE FROM cubit.purchases WHERE purid='{$purid}'"; if (!db_exec($sql)) { return false; } $sql = "INSERT INTO cubit.cancelled_purch(purid, deptid, supid, supaddr, terms, pdate, ddate, remarks, received, refno, vatinc, prd, ordernum, part, div, purnum, edit, supname, supno, shipchrg, subtot, total, balance, vat, supinv, apprv, appname, rvat, rshipchrg, rsubtot, rtotal, jobid, jobnum, toggle, cash, shipping, invcd, rshipping, noted, returned, iamount, ivat, delvat, username) VALUES('{$pur['purid']}', '{$pur['deptid']}', '{$pur['supid']}', '{$pur['supaddr']}', '{$pur['terms']}', '{$pur['pdate']}', '{$pur['ddate']}', '{$pur['remarks']}', '{$pur['received']}', '{$pur['refno']}', '{$pur['vatinc']}', '{$pur['prd']}', '{$pur['ordernum']}', '{$pur['part']}', '{$pur['div']}', '{$pur['purnum']}', '{$pur['edit']}', '{$pur['supname']}', '{$pur['supno']}', '{$pur['shipchrg']}', '{$pur['subtot']}', '{$pur['total']}', '{$pur['balance']}', '{$pur['vat']}', '{$pur['supinv']}', '{$pur['apprv']}', '{$pur['appname']}', '{$pur['rvat']}', '{$pur['rshipchrg']}', '{$pur['rsubtot']}', '{$pur['rtotal']}', '{$pur['jobid']}', '{$pur['jobnum']}', '{$pur['toggle']}', '{$pur['cash']}', '{$pur['shipping']}', '{$pur['invcd']}', '{$pur['rshipping']}', '{$pur['noted']}', '{$pur['returned']}', '{$pur['iamount']}', '{$pur['ivat']}', '{$pur['delvat']}', '{$userinfo['username']}')"; if (!db_exec($sql)) { return false; } $msg = "Purchase nr. {$pur['purnum']} denied."; print "Purchase denied\n"; } else { if ($purstatus == "a") { $msg = "Purchase nr. {$pur['purnum']} accepted. You should receive further information from supplier."; } else { if ($purstatus == "i") { $msg = "Purchase nr. {$pur['purnum']} accepted and invoiced. You should receive further information/an invoice from supplier."; } } } print "Sending msg: {$msg} to user: {$userinfo['username']}\n"; msgSend($userinfo["username"], $msg); }