function init($sA2Billing = null) { if ($sA2Billing) { $this->a2billing =& $sA2Billing; } else { $this->a2billing =& A2Billing::instance(); } if (isset($GLOBALS['FG_DEBUG'])) { $this->FG_DEBUG = $GLOBALS['FG_DEBUG']; } // Fill a local array with dirty versions of data.. if (!$this->prefix) { $this->_dirty_vars = array_merge($_GET, $_POST); } else { $tmp_arr = array_merge($_GET, $_POST); $tlen = strlen($this->prefix); $this->_dirty_vars = array(); // Find vars matching prefix and strip that! foreach ($tmp_arr as $key => $data) { if (strncmp($this->prefix, $key, $tlen) == 0) { $this->_dirty_vars[substr($key, $tlen)] = $data; } } } // set action, for a start: $this->action = $this->getpost_single('action'); if ($this->action == null) { $this->action = $this->action_ask; } }
function init($sA2Billing = null, $stdActions = true) { if (!$this->rights_checked) { error_log("Attempt to use Callshop w/o rights!"); die; } if ($sA2Billing) { $this->a2billing =& $sA2Billing; } else { $this->a2billing =& A2Billing::instance(); } if (isset($GLOBALS['FG_DEBUG'])) { $this->FG_DEBUG = $GLOBALS['FG_DEBUG']; } }
public function detailQueryField(&$dbhandle) { if ($this->fieldexpr) { $fld = $this->fieldexpr; } else { $fld = $this->fieldname; } return "format_currency2({$fld}, '" . A2Billing::instance()->currency . "') AS " . $this->fieldname; }
// $files = $cli_args['input']; // // if (empty($files)){ // echo "No file specified!\n"; // exit(1); // } // // $res= fopen($files[0],'r'); // if (!$res){ // echo "Could not open ".$files[0]." .\n"; // exit(2); // } define('DEBUG_CONF', 1); $host = A2Billing::instance()->set_def_conf($manager_section, 'host', 'localhost'); $uname = A2Billing::instance()->set_def_conf($manager_section, 'username', 'a2billing'); $password = A2Billing::instance()->set_def_conf($manager_section, 'secret', ''); if ($verbose > 2) { echo "Starting manager-eventd.\n"; } $num_tries = 0; while ($num_tries < 10) { $num_tries++; $dbh = A2Billing::DBHandle(); if (!$dbh) { echo "Cannot connect to database, exiting.."; break; } $as = new AGI_AsteriskManager(); if ($verbose < 2) { $as->nolog = true; } else {
if (!empty($cli_args['verbose']) || !empty($cli_args['v'])) { $verbose = 2; } else { if (!empty($cli_args['silent']) || !empty($cli_args['q'])) { $verbose = 0; } } } // print_r ($cli_args); // echo "verbose = $verbose - startdate=$startdate\n "; if (!empty($cli_args['config'])) { define('DEFAULT_A2BILLING_CONFIG', $cli_args['config']); } // Get the periods $proc_periods = $cli_args['input']; $A2B = A2Billing::instance(); $dbhandle = $A2B->DBHandle(); $back_days = 15; $amount_cdr = 100; $cdr_per_day = intval($amount_cdr / $back_days); $cardid = 3; $destination = 'Italy'; $calledstation = '397821933244'; for ($i = 1; $i <= $back_days; $i++) { echo "Day : {$i}...\n"; for ($j = 1; $j <= $cdr_per_day; $j++) { $maxhour = sprintf("%02d", rand(0, 23)); $minhour = sprintf("%02d", rand(0, 23)); if ($maxhour < $minhour) { $temp = $maxhour; $maxhour = $minhour;
function BoothsDom($action, $actb, $agent_clause = 'AND false') { global $FG_DEBUG; $dbhandle =& A2Billing::instance()->DBHandle(); // Prepare the XML DOM structure $dom = new DOMDocument("1.0", "utf-8"); // $_SESSION["pr_login"]; $dom_root = $dom->createElement("root"); $dom->appendChild($dom_root); $dom_message = $dom->createElement("message"); $dom_root->appendChild($dom_message); if (!empty($agent_clause)) { $aclause = ' AND ' . $agent_clause; } else { $aclause = ''; } $booth_states = array(); $booth_states[0] = array(_("N/A"), _("Not available, no cards configured.")); $booth_states[1] = array(_("Empty"), _("No customer attached.")); $booth_states[2] = array(_("Idle"), _("Customer attached, inactive")); $booth_states[3] = array(_("Ready"), _("Waiting for calls")); $booth_states[4] = array(_("Active"), _("Calls made, charged")); $booth_states[5] = array(_("Disabled"), _("Disabled by the agent")); $booth_states[6] = array(_("Stopped"), _("Calls made, charged, stopped")); // Perform the SQL query $message = ''; if (!empty($action)) { /* Here we handle all actions to the booths! */ $get_booth = -1; if (!empty($actb)) { $get_booth = (int) $actb; switch ($action) { case 'disable': $message = _("Booth disabled"); break; case 'stop': //$DBHandle->debug = true; $res = $dbhandle->Execute("UPDATE cc_booth_v SET state = 2 WHERE id = ? {$aclause};", array($get_booth)); if ($res) { $message = _("Booth stopped"); } else { $message = _("Action failed:"); //if ($FG_DEBUG) $message .= $dbhandle->ErrorMsg(); } break; case 'start': $res = $dbhandle->Execute("UPDATE cc_booth_v SET state = 3 WHERE id = ? {$aclause};", array($get_booth)); if ($res && $dbhandle->Affected_Rows()) { $message = _("Booth started"); } else { $message = _("Action failed:"); $message = $message . $dbhandle->ErrorMsg(); $message_class = "msg_error"; } break; case 'load_def': $res = $dbhandle->Execute("UPDATE cc_booth SET cur_card_id = def_card_id WHERE id = ? {$aclause};", array($get_booth)); if ($res && $dbhandle->Affected_Rows()) { $message = _("Booth started"); } else { $message = _("Action failed:"); $message = $message . $dbhandle->ErrorMsg(); $message_class = "msg_error"; } break; case 'load_reg': $res = $dbhandle->Execute("UPDATE cc_booth SET cur_card_id = ? WHERE id = ? {$aclause};", array($_GET['card'], $get_booth)); if ($res && $dbhandle->Affected_Rows()) { $message = _("Booth started"); } else { $message = _("Action failed:"); $message .= $dbhandle->ErrorMsg(); // $message .= "<br>Query: " . $query; $message_class = "msg_error"; } break; case 'refill': $rf = (double) $_GET['sum']; if ($rf <= 0.0 || $rf > 50.0) { $message = _("Invalid sum for refill"); $message_class = "msg_error"; } else { $get_booth = (int) $actb; $query = "INSERT INTO cc_agentrefill(agentid, boothid, credit, pay_type) " . "SELECT agentid, cc_booth.id, conv_currency_from(?, cc_agent.currency), " . "(SELECT id FROM cc_paytypes WHERE preset = 'prepay') " . "FROM cc_booth, cc_agent WHERE cc_booth.id = ? AND cc_agent.id = cc_booth.agentid {$aclause};"; $res = $dbhandle->Execute($query, array($rf, $get_booth)); if ($res && $dbhandle->Affected_Rows()) { $message = _("Credit added to booth"); $message_class = "msg_success"; } else { $message = _("Refill failed: do you have enough credit?"); if ($FG_DEBUG) { $message .= "<br>" . $dbhandle->ErrorMsg(); } if ($FG_DEBUG > 2) { $message .= " <br>QUERY= " . $query; } $message_class = "msg_error"; } } break; case 'empty': $res = $dbhandle->Execute("UPDATE cc_booth SET cur_card_id = NULL WHERE id = ? {$aclause};", array($get_booth)); if ($res && $dbhandle->Affected_Rows()) { $message = _("Booth emptied"); } else { $message = _("Action failed:"); $message .= $DBHandle->ErrorMsg(); //$message .= "<br>Query: " . $query; $message_class = "msg_error"; } break; default: $message = "Unknown request"; $message_class = "msg_error"; } } else { switch ($action) { default: $message = "Incorrect request"; } } } $QUERY = "SELECT id, name, state, secs, format_currency(COALESCE(credit,0), currency) AS credit, in_now "; $QUERY .= " FROM cc_booth_v WHERE def_card_id IS NOT NULL {$aclause} ORDER BY id;"; $res = $dbhandle->query($QUERY); // $dom_message->appendChild($dom->createTextNode($QUERY)); // $dom_message->setAttribute("class","msg_errror"); if (!$res) { $message = _("Database query failed!"); if ($FG_DEBUG) { $message .= $dbhandle->ErrorMsg(); } if ($FG_DEBUG > 2) { $message .= '<br>' . htmlspecialchars($QUERY); } $dom_message->appendChild($dom->createTextNode($message)); $dom_message->setAttribute("class", "msg_errror"); } elseif ($res->EOF) { $message = _("Database query failed!"); if ($FG_DEBUG) { $message .= "No rows returned!"; } $dom_message->appendChild($dom->createTextNode($message)); $dom_message->setAttribute("class", "msg_errror"); } else { $dom_message->appendChild($dom->createTextNode($message)); if (isset($message_class)) { $dom_message->setAttribute("class", $message_class); } // if (!isset($currencies_list[strtoupper($customer_info [14])][2]) || !is_numeric($currencies_list[strtoupper($customer_info [14])][2])) $mycur = 1; // else $mycur = $currencies_list[strtoupper($customer_info [14])][2]; $buttons = array(); $buttons['sta'] = false; $buttons['stp'] = false; $buttons['pay'] = false; $buttons['en'] = false; $buttons['dis'] = false; $buttons['unl'] = false; $buttons['ld'] = false; $buttons['lr'] = false; $buttons['emp'] = false; $buttons['ln'] = false; $num = $res->numRows(); for ($i = 0; $i < $num; $i++) { $row = $res->fetchRow(); $dom_booth = $dom->createElement("booth"); $dom_root->appendChild($dom_booth); $dom_booth->setAttribute("id", "booth_" . $row['id']); $tmp = $dom->createElement("name"); $name = $row['name']; if (!empty($row['in_now'])) { $name .= ' (' . $row['in_now'] . ')'; } $tmp->appendChild($dom->createTextNode($name)); $dom_booth->appendChild($tmp); $tmp = $dom->createElement("status"); $row_state = $row['state']; if ($row_state < 0 || $row_state > 6) { $row_state = 0; } $tmp->appendChild($dom->createTextNode($booth_states[$row_state][0])); //$tmp->setAttribute("alt",$booth_states[$row_state][1]); $tmp->setAttribute("class", "state" . $row_state); $dom_booth->appendChild($tmp); $tmp = $dom->createElement("mins"); $tmp->appendChild($dom->createTextNode(fmt_minutes($row['secs']))); $dom_booth->appendChild($tmp); $tmp = $dom->createElement("credit"); $tmp->appendChild($dom->createTextNode($row['credit'])); $dom_booth->appendChild($tmp); // switch off all buttons foreach ($buttons as &$bu) { $bu = false; } $td_refill = false; // select the ones that will be visible switch ($row_state) { case 0: break; case 1: $buttons["ld"] = true; $buttons["lr"] = true; //$buttons["ln"]=true; //$buttons["dis"]=true; break; case 2: $buttons["sta"] = true; $buttons["emp"] = true; //$buttons["lr"]=true; //$buttons["ld"]=true; $td_refill = true; break; case 3: $buttons["stp"] = true; $buttons['emp'] = true; $td_refill = true; break; case 4: $buttons["pay"] = true; $buttons["stp"] = true; break; case 5: $buttons["en"] = true; break; case 6: $buttons["pay"] = true; $buttons["sta"] = true; $td_refill = true; } foreach ($buttons as $key => $bu) { $tmp = $dom->createElement("button_" . $key); $tmp->setAttribute("display", $bu ? "inline" : "none"); $dom_booth->appendChild($tmp); } $tmp = $dom->createElement("refill"); $tmp->setAttribute("display", $td_refill ? "inline" : "none"); $dom_booth->appendChild($tmp); } } return $dom; }
function init($sA2Billing = null, $stdActions = true) { if (!$this->rights_checked) { error_log("Attempt to use FormHandler w/o rights!"); die; } if ($sA2Billing) { $this->a2billing =& $sA2Billing; } else { $this->a2billing =& A2Billing::instance(); } if (isset($GLOBALS['FG_DEBUG'])) { $this->FG_DEBUG = $GLOBALS['FG_DEBUG']; } // Fill a local array with dirty versions of data.. if (!$this->prefix) { $this->_dirty_vars = array_merge($_GET, $_POST); } else { $tmp_arr = array_merge($_GET, $_POST); $tlen = strlen($this->prefix); $this->_dirty_vars = array(); // Find vars matching prefix and strip that! foreach ($tmp_arr as $key => $data) { if (strncmp($this->prefix, $key, $tlen) == 0) { $this->_dirty_vars[substr($key, $tlen)] = $data; } } } // set action, for a start: $this->action = $this->getpost_single('action'); if ($this->action == null) { $this->action = 'list'; } if ($this->order = $this->getpost_single('order')) { $this->addFollowParam('order', $this->order); } else { $this->order = $this->default_order; } if ($this->sens = $this->getpost_single('sens')) { $this->addFollowParam('sens', $this->sens); } else { $this->sens = $this->default_sens; } if ($this->cpage = $this->getpost_single('cpage')) { $this->addFollowParam('cpage', $this->cpage); } if ($this->ndisp = $this->getpost_single('ndisp')) { $this->addFollowParam('ndisp', $this->ndisp); } else { $this->ndisp = 30; } if ($stdActions) { $this->views['idle'] = new IdleView(); $this->views['list'] = new ListView(); if (!session_readonly()) { $this->views['edit'] = new EditView(); $this->views['add'] = new AddView(); $this->views['delete'] = new DeleteView(); $this->views['object-edit'] = new ObjEditView(); } $this->views['ask-add'] = new AskAddView(); $this->views['ask-add2'] = new AskAdd2View(); $this->views['ask-edit2'] = new AskEdit2View(); $this->views['ask-edit'] = new AskEditView(); $this->views['ask-del'] = new AskDelView(); $this->views['details'] = new DetailsView(); if ($this->FG_DEBUG) { $this->views['dump-form'] = new DbgDumpView(); } } }
// require_once (DIR_COMMON."Form/Class.SqlRefField.inc.php"); require_once DIR_COMMON . "Form/Class.TimeField.inc.php"; require_once DIR_COMMON . "Form/Class.ClauseField.inc.php"; require_once DIR_COMMON . "Form/Class.ListSumView.inc.php"; require_once DIR_COMMON . "Form/Class.SumMultiView.inc.php"; require_once DIR_COMMON . "Class.SqlActionElem.inc.php"; require_once DIR_COMMON . "SessionInvoice.inc.php"; $menu_section = 'menu_payments'; //HelpElem::DoHelp(gettext("Agents, callshops. <br>List or manipulate agents, which can deliver cards to customers.")); $sess_row = false; $dbg_elem = new DbgElem(); $dbhandle = A2Billing::DBHandle(); if ($FG_DEBUG > 0) { $PAGE_ELEMS[] =& $dbg_elem; } $sessqry = "SELECT is_open, sid, booth, card, is_inuse, credit, " . " ( duration >= interval '1 day') AS has_days, " . str_dbparams($dbhandle, " format_currency(credit,%1) AS credit_fmt ", array(A2Billing::instance()->currency)) . " FROM cc_shopsession_status_v " . " WHERE agentid = " . $_SESSION['agent_id']; if (isset($_GET['booth'])) { $sessqry .= str_dbparams($dbhandle, ' AND booth = %#1 ', array($_GET['booth'])); } elseif (isset($_GET['sid'])) { $sessqry .= str_dbparams($dbhandle, ' AND sid = %#1 ', array($_GET['sid'])); } $sessqry .= ' ORDER BY sid DESC LIMIT 1;'; if ($FG_DEBUG > 2) { $dbg_elem->content .= "Query: " . $sessqry . "\n"; } $sess_res = $dbhandle->Execute($sessqry); if (!$sess_res) { $dbg_elem->content .= $dbhandle->ErrorMsg(); $PAGE_ELEMS[] = new ErrorElem(_("Cannot locate session!")); } elseif ($sess_res->EOF) { $dbg_elem->content .= "No data found!";
function AgentMoney($agentid, &$sel_form, $intl, $rights) { global $PAGE_ELEMS; global $FG_DEBUG; $dbhandle = A2Billing::DBHandle(); $HD_Form = new FormHandler('cc_agent_money_v', _("Transactions"), _("Transaction")); $HD_Form->checkRights($rights); $HD_Form->init(null, false); $HD_Form->views['list'] = new SumMultiView(); $HD_Form->views['pay'] = $HD_Form->views['true'] = $HD_Form->views['false'] = new IdleView(); if ($FG_DEBUG) { $HD_Form->views['dump-form'] = new DbgDumpView(); } $clauses = $sel_form->buildClauses(); // $PAGE_ELEMS[] = new DbgElem(print_r($clauses,true)); $PAGE_ELEMS[] =& $HD_Form; $HD_Form->model[] = new ClauseField('agentid', $agentid); if (isset($clauses['date_from'])) { $HD_Form->model[] = new FreeClauseField($clauses['date_from']); } if (isset($clauses['date_to'])) { $HD_Form->model[] = new FreeClauseField($clauses['date_to']); } $HD_Form->model[] = new DateTimeField(_("Date"), 'date'); $HD_Form->model[] = new TextField(_("Type"), 'pay_type'); if ($intl) { end($HD_Form->model)->fieldexpr = 'gettexti(pay_type,\'' . getenv('LANG') . '\')'; } else { end($HD_Form->model)->fieldexpr = 'gettexti(pay_type,\'C\')'; } $HD_Form->model[] = new TextField(_("Description"), 'descr'); if ($intl) { end($HD_Form->model)->fieldexpr = 'gettext(descr,\'' . getenv('LANG') . '\')'; } $HD_Form->model[] = new MoneyField(_("In"), 'pos_credit'); $HD_Form->model[] = new MoneyField(_("Out"), 'neg_credit'); $HD_Form->model[] = new MoneyField(_("Sum"), 'credit'); $HD_Form->views['list']->sums[] = array('group' => false, 'fns' => array('date' => true, 'pay_type' => true, 'descr' => true, 'pos_credit' => true, 'neg_credit' => true)); $HD_Form->views['list']->sums[] = array('fns' => array('descr' => array(_("Totals")), 'pos_credit' => 'SUM', 'neg_credit' => 'SUM')); $HD_Form->views['list']->sums[] = array('fns' => array('descr' => array(_("Sum Total")), 'credit' => 'SUM')); $Totals = new SqlDetailsActionForm(); $Totals->checkRights($rights); $Totals->init(); $Totals->setAction('true'); $PAGE_ELEMS[] =& $Totals; $Totals->expectRows = false; $Totals->listclass = 'total'; $Totals->headerString = _("Agent Totals"); $Totals->successString = null; $dc2 = ''; if (isset($clauses['date_from'])) { $dc2 .= ' AND ' . str_replace('date ', 'starttime ', $clauses['date_from']); } if (isset($clauses['date_to'])) { $dc2 .= ' AND ' . str_replace('date ', 'starttime ', $clauses['date_to']); } $cardsqr = "SELECT SUM(CASE WHEN credit > 0.0 THEN credit ELSE NULL END) AS pos_credit,\n\t\t\tSUM(CASE WHEN credit < 0.0 THEN (0.0 - credit) ELSE NULL END) AS neg_credit,\n\t\t\tSUM(creditlimit) AS climit\n\t\t\tFROM cc_card, cc_card_group\n\t\t\tWHERE cc_card.grp = cc_card_group.id AND cc_card_group.agentid IS NOT NULL\n\t\t\tAND agentid = %1"; $callsqr = "SELECT SUM(sessionbill) AS calls \n\t\t\tFROM cc_call, cc_card, cc_card_group \n\t\t\tWHERE cc_call.cardid = cc_card.id AND cc_card_group.id = cc_card.grp\n\t\t\t\tAND cc_card_group.agentid = %1 " . $dc2; $dleftqr = "cc_calc_daysleft(%1,now(), interval '1 month')"; $Totals->QueryString = str_dbparams($dbhandle, "SELECT format_currency(tc.pos_credit, %2) AS total_ccredit,\n\t\t format_currency(tc.neg_credit, %2) AS total_cdebit, " . "format_currency(tc.climit, %2) AS total_cclimit,\n\t\tformat_currency(sb.calls,%2) AS total_calls, format_currency((sb.calls * cc_agent.commission), %2) AS total_com,\n\t\tformat_currency((sb.calls * (1.0 - cc_agent.commission)), %2) AS total_wh,\n\t\tformat_currency(cc_agent.credit, %2) AS agent_credit, format_currency(cc_agent.climit, %2) AS climit, dleft.days_left\n\t\t FROM ({$cardsqr}) AS tc, ({$callsqr}) AS sb, cc_agent, {$dleftqr} AS dleft\n\t\t WHERE cc_agent.id = %1;", array($agentid, A2Billing::instance()->currency)); $Totals->noRowsString = _("Totals could not be calculated!"); $Totals->rmodel[] = new MoneyField(_("Total sum credited to customers"), 'total_ccredit'); $Totals->rmodel[] = new MoneyField(_("Total sum debited from customers"), 'total_cdebit'); $Totals->rmodel[] = new MoneyField(_("Total potential debit from customers"), 'total_cclimit'); $Totals->rmodel[] = new IntField(_("Total calls made by customers"), 'total_calls'); $Totals->rmodel[] = new MoneyField(_("Wholesale price of calls"), 'total_wh'); $Totals->rmodel[] = new MoneyField(_("Estimated profit from calls"), 'total_com'); $Totals->rmodel[] = new MoneyField(_("Outstanding balance"), 'agent_credit'); $Totals->rmodel[] = new MoneyField(_("Credit Limit"), 'climit'); $Totals->rmodel[] = new IntField(_("Estimated Days left"), 'days_left'); // if ($vat>0) echo " (" .gettext("includes VAT"). "$vat %)"; }
$HD_Form->model[] = dontList(new MoneyField(_("Amount"), 'amount')); $HD_Form->model[] = dontList(new MoneyField(_("Tax"), 'tax')); $HD_Form->model[] = new MoneyField(_("Total"), 'total'); $HD_Form->model[] = new IntFieldN(_("Type"), "invoicetype"); //end($HD_Form->model)->refclause = "lang = 'C'"; $HD_Form->model[] = dontList(new TextFieldN(_("Filename"), "filename")); //$HD_Form->model[] = new SqlBigRefField(_("Invoice"), "invoice_id","cc_invoices", "id", "orderref"); //end($HD_Form->model)->refclause = "agentid IS NOT NULL"; //$HD_Form->model[] = dontList( new TextAreaField(_("Description"),'descr')); $ilist = array(); $ilist[] = array("0", _("Unpaid")); $ilist[] = array('1', _('Sent-unpaid')); $ilist[] = array('2', _('Sent-paid')); $ilist[] = array('3', _('Paid')); $HD_Form->model[] = new RefField(_("Status"), 'payment_status', $ilist); $HD_Form->model[] = new HiddenField(NULL, 'total_t', 'conv_currency_from(total,\'' . A2Billing::instance()->currency . '\')'); $detBtn = new OtherBtnField(); $detBtn->title = _("View"); $detBtn->url = "invoices_agent.php?"; $detBtn->extra_params = array('id' => 'id'); $obf = new OtherBtnField(); $obf->title = _("Pay"); $obf->url = "A2B_entity_agentpay.php?action=ask-add&"; $obf->extra_params = array('invoice_id' => 'id', 'agentid' => 'agentid', 'credit' => 'total_t'); $HD_Form->model[] = new GroupField(array($detBtn, $obf, new DelBtnField())); require "PP_page.inc.php"; if (false) { ?> <br> <script language="javascript"> function go(URL)
error_reporting(E_ALL); $verbose_mode = true; array_shift($argv); $argc--; } if ($argc > 1 && $argv[1] == '--test') { AGI::verbose_s("Testing mode!", 0); define('DEFAULT_CONFIG', "../a2billing.conf"); array_shift($argv); $argc--; } else { define('DEFAULT_CONFIG', '/etc/a2billing.conf'); } require_once 'Class.A2Billing.inc.php'; // create the objects $a2b = A2Billing::instance(); if (!$a2b->load_res_dbsettings('/etc/asterisk/res_pgsql.conf')) { @syslog(LOG_ERR, "Cannot fetch settings from res_pgsql.conf"); exit(2); } $dynconf = DynConf::instance(); if ($argc > 1 && is_numeric($argv[1]) && $argv[1] >= 0) { $idconfig = $argv[1]; } else { $idconfig = 1; } try { $dynconf->init(); $dynconf->PrefetchGroup('agiconf' . $idconfig); } catch (Exception $ex) { error_log($ex->getMessage());