コード例 #1
0
 public function register($result)
 {
     // validate input + additional validation
     $jsonval = new JsonValidate($this->data, '{"name":"", "email":"@", "address":"", "suburb":"", "postcode":"", "state":"", "country":"", "pass":"", "captcha":""}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     if (!$this->data->phone && !$this->data->mobile) {
         $result['error'] = "At least one contact phone number must be specified.";
         return $result;
     }
     // validate captcha
     require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['APP_ROOT'] . 'assets/secureimage/securimage.php';
     $img = new Securimage();
     // if the code checked is correct, it is destroyed to prevent re-use
     if ($img->check($this->data->captcha) == false) {
         $result['error'] = "Incorrect security code entered";
         return $result;
     }
     // create customer, check for error ( this does email check)
     $wposCust = new WposAdminCustomers();
     $res = $wposCust->addCustomerData($this->data);
     if (!is_numeric($res)) {
         $result['error'] = $res;
         return $result;
     }
     // set activation url with random hash as a token
     $token = WposAdminUtilities::getToken();
     $link = "https://" . $_SERVER['SERVER_NAME'] . "/myaccount/activate.php?token=" . $token;
     // set token
     $custMdl = new CustomerModel();
     if ($custMdl->setAuthToken($res, $token) === false) {
         $result['error'] = "Could not set auth token: " . $custMdl->errorInfo;
     }
     // send reset email
     $linkhtml = '<a href="' . $link . '">' . $link . '</a>';
     $mailer = new WposMail();
     if (($mres = $mailer->sendPredefinedMessage($this->data->email, 'register_email', ['name' => $this->data->name, 'link' => $linkhtml])) !== true) {
         $result['error'] = $mres;
     }
     $mailer->sendPredefinedMessage("*****@*****.**", 'register_notify', ['name' => "Michael", 'custname' => $this->data->name]);
     return $result;
 }
コード例 #2
0
ファイル: TestData.php プロジェクト: cosmospham/wallacepos
 public function generate($numtransactions, $type = 'sale')
 {
     // get dependant record
     $this->getRecords();
     // set cur time
     $curprocessdt = time() * 1000;
     if (date('D', $curprocessdt) > 16) {
         $curprocessdt = strtotime(date("Y-m-d", $curprocessdt / 1000) . " 17:00:00") * 1000;
     }
     $initprocessdt = $curprocessdt;
     for ($i = 0; $i < $numtransactions; $i++) {
         // contruct JSON test data
         $saleobj = new stdClass();
         $saleobj->processdt = $curprocessdt;
         // pick a random device if  pos sale
         if ($type == 'sale') {
             $device = $this->devices[rand(0, sizeof($this->devices) - 1)];
             $saleobj->devid = $device['id'];
             $saleobj->locid = $device['locationid'];
         }
         $saleobj->ref = $curprocessdt . "-" . ($type == 'sale' ? $device['id'] : 0) . "-" . rand(1000, 9999);
         // pick a random user
         $saleobj->userid = $this->users[rand(0, sizeof($this->users) - 1)]['id'];
         // add misc data
         $saleobj->custid = "";
         $saleobj->custemail = "";
         $saleobj->notes = "";
         $saleobj->discount = 0;
         $saleobj->discountval = 0;
         // add random items
         $numitems = rand(1, 100) > 75 ? rand(1, 100) > 95 ? rand(7, 10) : rand(4, 6) : rand(1, 3);
         $totalitemqty = 0;
         $total = 0.0;
         $totaltax = 0.0;
         $taxes = [];
         $items = [];
         // loop through num items time
         for ($inum = 0; $inum < $numitems; $inum++) {
             $item = $this->items[rand(0, sizeof($this->items) - 1)];
             // If price is 0 or "" pick a random price
             if ($item['price'] == "" || $item['price'] == 0) {
                 $item['price'] = rand(1, 100);
             }
             // select random qty and get item total
             $randqty = rand(1, 100);
             $qty = $randqty > 80 ? $randqty > 95 ? 3 : 2 : 1;
             $totalitemqty += $qty;
             $itemtotal = round($item['price'] * $qty, 2);
             // work out tax and add totals
             $itemtax = WposAdminUtilities::calculateTax($item['taxid'], isset($saleobj->locid) ? $saleobj->locid : 0, $itemtotal);
             if (!$itemtax->inclusive) {
                 $itemtotal += $itemtax->total;
             }
             $total += $itemtotal;
             $totaltax += $itemtax->total;
             foreach ($itemtax->values as $key => $value) {
                 if (isset($taxes[$key])) {
                     $taxes[$key] += $value;
                 } else {
                     $taxes[$key] = $value;
                 }
             }
             $itemObj = new stdClass();
             $itemObj->ref = $inum + 1;
             $itemObj->sitemid = $item['id'];
             $itemObj->qty = $qty;
             $itemObj->name = $item['name'];
             $itemObj->desc = $item['description'];
             $itemObj->unit = $item['price'];
             $itemObj->taxid = $item['taxid'];
             $itemObj->tax = $itemtax;
             $itemObj->price = $itemtotal;
             $items[] = $itemObj;
         }
         $saleobj->items = $items;
         $subtotal = $total - $totaltax;
         // if method cash round the total & add rounding amount, no cash payments for invoices
         if ($type == 'sale') {
             $paymethod = $this->paymentMethods[rand(0, sizeof($this->paymentMethods) - 1)];
         } else {
             $paymethod = $this->paymentMethods[rand(0, sizeof($this->paymentMethods) - 2)];
         }
         if ($type == 'sale' && $paymethod == "cash") {
             // round to nearest five cents
             $temptotal = $total;
             $total = round($total / 0.05) * 0.05;
             $saleobj->rounding = number_format($total - $temptotal, 2, '.', '');
             //if (floatval($saleobj->rounding)!=0)
             //echo($temptotal." ".$total."<br/>");
         } else {
             $saleobj->rounding = 0.0;
         }
         // add payment to the sale
         if ($type == 'sale') {
             // leave a few invoices unpaid.
             $payment = new stdClass();
             $payment->method = $paymethod;
             $payment->amount = number_format($total, 2, '.', '');
             if ($paymethod == "cash") {
                 $tender = round($total) % 5 === 0 ? round($total) : round(($total + 5 / 2) / 5) * 5;
                 $payment->tender = number_format($tender, 2, '.', '');
                 $payment->change = number_format($tender - $total, 2, '.', '');
             }
             $saleobj->payments = [$payment];
         } else {
             if ($type == 'invoice') {
                 if ($i < 2 || $i == 60) {
                     $saleobj->payments = [];
                 } else {
                     $payment = new stdClass();
                     $payment->method = $paymethod == 'cash' ? 'eftpos' : $paymethod;
                     $payment->amount = number_format($total, 2, '.', '');
                     $saleobj->payments = [$payment];
                 }
             }
         }
         // add totals and tax
         $saleobj->numitems = $totalitemqty;
         $saleobj->taxdata = $taxes;
         $saleobj->tax = number_format($totaltax, 2, '.', '');
         $saleobj->subtotal = number_format($subtotal, 2, '.', '');
         $saleobj->total = number_format($total, 2, '.', '');
         // randomly add a void/refund to the sale
         if ($type == 'sale' && rand(1, 30) == 1) {
             $voidobj = new stdClass();
             // pick another random device
             $device = $this->devices[rand(0, sizeof($this->devices) - 1)];
             $voidobj->deviceid = $device['id'];
             $voidobj->locationid = $device['locationid'];
             // pick another random user
             $voidobj->userid = $this->users[rand(0, sizeof($this->users) - 1)]['id'];
             // set sometime in the future but do not set before the initial date (now).
             $voidobj->processdt = $curprocessdt + rand(30, 60 * 24) > $initprocessdt ? $initprocessdt : $curprocessdt + rand(30, 60 * 24);
             if (rand(1, 2) == 1) {
                 // add reason
                 $voidobj->reason = "Faulty Item";
                 // refund, add additional data
                 $voidobj->method = $this->paymentMethods[rand(0, sizeof($this->paymentMethods) - 1)];
                 // pick item to return
                 $retitem = $items[rand(0, sizeof($items) - 1)];
                 $itemdata = new stdClass();
                 $itemdata->numreturned = 1;
                 $itemdata->ref = $retitem->ref;
                 $voidobj->items = [$itemdata];
                 $voidobj->amount = $retitem->unit;
                 // put in array before adding to saleobj
                 $saleobj->refunddata = [$voidobj];
             } else {
                 // add reason
                 $voidobj->reason = "Mistake";
                 // void
                 $saleobj->voiddata = $voidobj;
             }
         }
         // process the sale
         if ($type == 'sale') {
             $this->wposSales = new WposPosSale($saleobj);
             $this->wposSales->setNoBroadcast();
             $result = $this->wposSales->insertTransaction(["errorCode" => "OK", "error" => "OK", "data" => ""]);
             //echo("Sale created: ".json_encode($result)."<br/>");
         } else {
             // add invoice only fields
             $saleobj->duedt = $curprocessdt + 1209600000;
             $saleobj->custid = rand(1, 2);
             $saleobj->channel = "manual";
             $this->wposSales = new WposInvoices($saleobj, null, true);
             $result = $this->wposSales->createInvoice(["errorCode" => "OK", "error" => "OK", "data" => ""]);
             //echo("Invoice created: ".json_encode($result));
         }
         // decrement by a random time between 2-40 minutes
         if ($type == 'sale') {
             $curprocessdt = $curprocessdt - rand(2, 40) * 60 * 1000;
         } else {
             $curprocessdt = $curprocessdt - rand(40, 280) * 60 * 1000;
         }
         // if it's before shop open time, decrement to the last days closing time.
         $hour = date("H", $curprocessdt / 1000);
         if ($hour < 9) {
             $curprocessdt = strtotime(date("Y-m-d", $curprocessdt / 1000 - 86400) . " 17:00:00") * 1000;
         }
     }
     return;
 }
コード例 #3
0
ファイル: WposPosSale.php プロジェクト: cosmospham/wallacepos
 /**
  * Email the sale receipt to the specified address
  * @param $email
  * @return mixed
  */
 private function emailReceipt($email)
 {
     // get config
     $config = new WposAdminSettings();
     $recval = $config->getSettingsObject("pos");
     $genval = $config->getSettingsObject("general");
     $utils = new WposAdminUtilities();
     $utils->setCurrencyFormat($genval->currencyformat);
     // create receipt
     $html = '<div style="padding: 10px; padding-left: 5px; padding-right: 5px; margin-top:5px; width:300px; margin: auto; background-color:#FFFFFF;"><img width="95%" src="http://' . $_SERVER['SERVER_ADDR'] . $recval->recemaillogo . '"/><br/>';
     $html .= '<h3 style="text-align: center; margin: 5px;">' . $genval->bizname . '</h3>';
     $html .= '<p style="text-align: center"><strong>' . $recval->recline2 . '</strong>';
     if ($recval->recline3 != "") {
         $html .= '<br/><strong style="text-align: center">' . $recval->recline3 . '</strong>';
     }
     $html .= '</p>';
     // body
     $html .= '<p style="padding-top: 5px;">Transaction Ref:&nbsp;&nbsp;' . $this->ref . '<br/>';
     $html .= 'Sale Time:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . WposAdminUtilities::getDateFromTimeStamp($this->jsonobj->processdt, $genval->dateformat) . '</p>';
     // items
     $html .= '<table style="width: 100%; margin-bottom: 4px; font-size: 13px;">';
     foreach ($this->jsonobj->items as $item) {
         // item mod details
         $modStr = "";
         if (isset($item->mod)) {
             foreach ($item->mod->items as $mod) {
                 $modStr .= '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . (isset($mod->qty) ? ($mod->qty > 0 ? '+ ' : '') . $mod->qty . ' ' : '') . $mod->name . (isset($mod->value) ? ': ' . $mod->value : '') . ' (' . $utils->currencyFormat($mod->price) . ')';
             }
         }
         $html .= '<tr><td>' . $item->qty . "x " . $item->name . " (" . $utils->currencyFormat($item->unit) . ")" . $modStr . '</td><td style="text-align: right;">' . $utils->currencyFormat($item->price) . '</td></tr>';
     }
     $html .= '<tr style="height: 5px;"><td></td><td></td></tr>';
     // totals
     // subtotal
     $taxcount = count(get_object_vars($this->jsonobj->taxdata));
     if ($taxcount > 0 || $this->jsonobj->discount > 0) {
         // only add if discount or taxes
         $html .= '<tr><td><b>Subtotal: </b></td><td style="text-align: right;"><b style="text-decoration: overline;">' . $utils->currencyFormat($this->jsonobj->subtotal) . '</b></td></tr>';
     }
     // taxes
     if ($taxcount) {
         $taxMdl = new TaxItemsModel();
         $taxes = $taxMdl->get();
         foreach ($taxes as $tax) {
             $taxes[$tax['id']] = $tax;
         }
         foreach ($this->jsonobj->taxdata as $key => $tax) {
             $taxstr = $taxes[$key];
             $taxstr = $taxstr['name'] . ' (' . $taxstr['value'] . '%)';
             $html .= '<tr><td>' . $taxstr . ':</td><td style="text-align: right;">' . $utils->currencyFormat($tax) . '</td></tr>';
         }
     }
     // discount
     $html .= $this->jsonobj->discount > 0 ? '<tr><td>' . $this->jsonobj->discount . '% Discount</td><td style="text-align: right;">' . $utils->currencyFormat(abs(floatval($this->jsonobj->total) - (floatval($this->jsonobj->subtotal) + floatval($this->jsonobj->tax)))) . '</td></tr>' : '';
     // grand total
     $html .= '<tr><td><b>Total (' . $this->jsonobj->numitems . ' items): </b></td><td style="text-align: right;"><b style="text-decoration: overline;">' . $utils->currencyFormat($this->jsonobj->total) . '</b></td></tr>';
     $html .= '<tr style="height: 2px;"><td></td><td></td></tr>';
     // payments
     foreach ($this->jsonobj->payments as $payment) {
         $html .= '<tr><td><span style="font-size: 14px;">' . ucfirst($payment->method) . '</p></td><td style="text-align: right;"><p style="font-size: 14px;">' . $utils->currencyFormat($payment->amount) . '</span></td></tr>';
         if ($payment->method == 'cash') {
             // If cash print tender & change
             $html .= '<tr><td>Tendered:</td><td style="text-align: right;">' . $utils->currencyFormat($payment->tender) . '</td></tr>';
             $html .= '<tr><td>Change:</td><td style="text-align: right;">' . $utils->currencyFormat($payment->change) . '</td></tr>';
         }
     }
     $html .= '</table>';
     // refunds
     if (isset($this->jsonobj->refunddata)) {
         $html .= '<p style="margin-top: 0; margin-bottom: 5px; font-size: 13px;"><strong>Refund</strong></p><table style="width: 100%; font-size: 13px;">';
         foreach ($this->jsonobj->refundata as $refund) {
             $html .= '<tr><td>' . WposAdminUtilities::getDateFromTimeStamp($refund->processdt, $genval->dateformat) . ' (' . sizeof($refund->items) . ' items)</td><td>' . ucfirst($refund->method) . '<span style="float: right;">' . $refund->amount . '</span></td></tr>';
         }
         $html .= '</table>';
     }
     // void
     if (isset($this->jsonobj->voiddata)) {
         $html .= '<h2 style="text-align: center; color: #dc322f; margin-top: 5px;">VOID SALE</h2>';
     }
     // footer
     $html .= '<p style="text-align: center;"><strong>' . $recval->recfooter . '</strong><br/>';
     if ($recval->recqrcode != "") {
         $html .= '<img style="text-align: center;" height="99" src="http://' . $_SERVER['SERVER_ADDR'] . '/wpos/asset/images/qrcode.png"/>';
     }
     $html .= '</p></div>';
     $template = '<html><head><link media="all" href="https://' . $_SERVER['SERVER_NAME'] . '/wpos/admin/assets/css/bootstrap.min.css" rel="stylesheet"/><link media="all" rel="stylesheet" href="https://' . $_SERVER['SERVER_NAME'] . '/wpos/admin/assets/css/font-awesome.min.css"/><link media="all" rel="stylesheet" href="https://' . $_SERVER['SERVER_NAME'] . '/wpos/admin/assets/css/ace-fonts.css"/><link media="all" rel="stylesheet" href="https://' . $_SERVER['SERVER_ADDR'] . '/wpos/admin/assets/css/ace.min.css"/></head><body>%message%</body>';
     $html = str_replace("%message%", $html, $template);
     $wposMail = new WposMail($genval);
     if (($mresult = $wposMail->sendHtmlEmail($email, 'Your ' . $genval->bizname . ' receipt', $html)) !== true) {
         return 'Failed to email receipt: ' . $mresult;
     } else {
         return true;
     }
 }
コード例 #4
0
 /**
  * Send password reset email to customer
  * @param $result
  * @return mixed
  */
 public function sendResetEmail($result)
 {
     // validate input
     if (!is_numeric($this->data->id)) {
         $result['error'] = "A valid id must be supplied";
         return $result;
     }
     // get customer details
     $custMdl = new CustomerModel();
     $customer = $custMdl->get($this->data->id)[0];
     if (strpos($customer['email'], '@') === -1) {
         $result['error'] = "The customer does not have a valid email";
         return $result;
     }
     // generate url
     $token = WposAdminUtilities::getToken();
     $link = "https://" . $_SERVER['SERVER_NAME'] . "/myaccount/resetpassword.php?token=" . $token;
     // set token
     if ($custMdl->setAuthToken($this->data->id, $token) === false) {
         $result['error'] = "Could not set auth token: " . $custMdl->errorInfo;
     }
     // send reset email
     $linkhtml = '<a href="' . $link . '">' . $link . '</a>';
     $mailer = new WposMail();
     if (($mres = $mailer->sendPredefinedMessage($customer['email'], 'reset_email', ['name' => $customer['name'], 'link' => $linkhtml])) !== true) {
         $result['error'] = $mres;
     }
     return $result;
 }
コード例 #5
0
ファイル: Auth.php プロジェクト: razmir/wallacepos
 /**
  * Generate a new token and auth_hash, save the token in the database
  * @param $id
  * @param $password_hash
  */
 private function setNewSessionToken($id, $password_hash)
 {
     // create unique token
     $tokens = ['token' => WposAdminUtilities::getToken()];
     // create auth_hash
     $tokens['auth_hash'] = hash('sha256', $password_hash . $tokens['token']);
     // save tokens
     $this->authMdl->setAuthToken($id, $tokens['token']);
     $this->authTokens = $tokens;
 }
コード例 #6
0
 /**
  * Generate invoice html
  * @return string
  */
 private function generateInvoiceHtml()
 {
     // copy invoice data, set tax values
     /** @noinspection PhpUnusedLocalVariableInspection */
     $invoice = $this->trans;
     $taxMdl = new TaxItemsModel();
     $taxdata = $taxMdl->get();
     $taxes = [];
     foreach ($taxdata as $value) {
         $taxes[$value['id']] = (object) $value;
     }
     // Get general settings
     $config = new WposAdminSettings();
     $settings = $config->getSettingsObject("general");
     $settings->payinst = $config->getSettingsObject("invoice")->payinst;
     // Get customer record
     $custMdl = new CustomerModel();
     /** @noinspection PhpUnusedLocalVariableInspection */
     $customer = (object) $custMdl->get($this->trans->custid)[0];
     $utils = new WposAdminUtilities();
     $utils->setCurrencyFormat($settings->currencyformat);
     // start output buffer and capture template output
     ob_start();
     include $_SERVER['DOCUMENT_ROOT'] . "/docs/templates/invoice.php";
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }
コード例 #7
0
 /**
  * Gets tax information as a static variable
  * @return null
  */
 public static function getTaxTable()
 {
     if (self::$taxTable == null) {
         self::$taxTable = WposPosData::getTaxes([])['data'];
     }
     return self::$taxTable;
 }
コード例 #8
0
ファイル: wpos.php プロジェクト: razmir/wallacepos
/**
 * routes api calls and returns the result, allows for multiple API calls at once
 * @param $action
 * @param $data
 * @param $result
 * @return array|mixed
 */
function routeApiCall($action, $data, $result)
{
    global $auth;
    $notinprev = false;
    // Check for action in unprotected area (does not require permission)
    switch ($action) {
        // POS Specific
        case "config/get":
            $setup = new WposPosSetup($data);
            $result = $setup->getDeviceRecord($result);
            break;
        case "items/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getItems($result);
            break;
        case "sales/get":
            $jsondata = new WposPosData($data);
            $result = $jsondata->getSales($result);
            break;
        case "tax/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getTaxes($result);
            break;
        case "customers/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getCustomers($result);
            break;
        case "devices/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getPosDevices($result);
            break;
        case "locations/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getPosLocations($result);
            break;
        case "orders/set":
            $sale = new WposPosSale($data);
            $result = $sale->setOrder($result);
            break;
        case "orders/remove":
            $sale = new WposPosSale($data);
            $result = $sale->removeOrder($result);
            break;
        case "sales/add":
            $sale = new WposPosSale($data);
            $result = $sale->insertTransaction($result);
            break;
        case "sales/void":
            // also used for sale refunds
            $sale = new WposPosSale($data, false);
            $result = $sale->insertVoid($result);
            break;
        case "sales/search":
            $sale = new WposPosData();
            if (isset($data)) {
                $result = $sale->searchSales($data, $result);
            }
            break;
        case "sales/updatenotes":
            $sale = new WposPosSale($data, false);
            $result = $sale->updateTransationNotes($result);
            break;
        case "transactions/get":
            $trans = new WposTransactions($data);
            $result = $trans->getTransaction($result);
            break;
        default:
            $notinprev = true;
    }
    if ($notinprev == false) {
        // an action has been executed: return the data
        return $result;
    }
    // Check if user is allowed to use this API request
    if ($auth->isUserAllowed($action) === false) {
        $result['errorCode'] = "priv";
        $result['error'] = "You do not have permission to perform this action.";
        return $result;
    }
    // Check in permission protected API calls
    switch ($action) {
        // admin only
        // device setup
        case "devices/setup":
            $setup = new WposPosSetup($data);
            $result = $setup->setupDevice($result);
            break;
            // stored items
        // stored items
        case "adminconfig/get":
            $setupMdl = new WposPosSetup();
            $result = $setupMdl->getAdminConfig($result);
            break;
        case "items/add":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->addStoredItem($result);
            break;
        case "items/edit":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->updateStoredItem($result);
            break;
        case "items/delete":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->deleteStoredItem($result);
            break;
            // suppliers
        // suppliers
        case "suppliers/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getSuppliers($result);
            break;
        case "suppliers/add":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->addSupplier($result);
            break;
        case "suppliers/edit":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->updateSupplier($result);
            break;
        case "suppliers/delete":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->deleteSupplier($result);
            break;
            // suppliers
        // suppliers
        case "stock/get":
            $jsondata = new WposPosData();
            $result = $jsondata->getStock($result);
            break;
        case "stock/add":
            $stockMdl = new WposAdminStock($data);
            $result = $stockMdl->addStock($result);
            break;
        case "stock/set":
            $stockMdl = new WposAdminStock($data);
            $result = $stockMdl->setStockLevel($result);
            break;
        case "stock/transfer":
            $stockMdl = new WposAdminStock($data);
            $result = $stockMdl->transferStock($result);
            break;
        case "stock/history":
            $stockMdl = new WposAdminStock($data);
            $result = $stockMdl->getStockHistory($result);
            break;
            // customers
        // customers
        case "customers/add":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->addCustomer($result);
            break;
        case "customers/edit":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->updateCustomer($result);
            break;
        case "customers/delete":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->deleteCustomer($result);
            break;
        case "customers/contacts/add":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->addContact($result);
            break;
        case "customers/contacts/edit":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->updateContact($result);
            break;
        case "customers/contacts/delete":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->deleteContact($result);
            break;
            // TODO: Add to permissions
        // TODO: Add to permissions
        case "customers/setaccess":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->setAccess($result);
            break;
        case "customers/setpassword":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->setPassword($result);
            break;
        case "customers/sendreset":
            $custMdl = new WposAdminCustomers($data);
            $result = $custMdl->sendResetEmail($result);
            break;
            // End to-do
            // USERS
        // End to-do
        // USERS
        case "users/get":
            $data = new WposPosData();
            $result = $data->getUsers($result);
            break;
        case "users/add":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->addUser($result);
            break;
        case "users/edit":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->updateUser($result);
            break;
        case "users/delete":
            $adminMdl = new WposAdminItems($data);
            $result = $adminMdl->deleteUser($result);
            break;
        case "users/disable":
            $setup = new WposAdminItems($data);
            $result = $setup->setUserDisabled($result);
            break;
            // DEVICES
        // DEVICES
        case "devices/add":
            $setup = new WposPosSetup($data);
            $result = $setup->addDevice($result);
            break;
        case "devices/edit":
            $setup = new WposPosSetup($data);
            $result = $setup->updateDevice($result);
            break;
        case "devices/delete":
            $setup = new WposPosSetup($data);
            $result = $setup->deleteDevice($result);
            break;
        case "devices/disable":
            $setup = new WposPosSetup($data);
            $result = $setup->setDeviceDisabled($result);
            break;
            // LOCATIONS
        // LOCATIONS
        case "locations/add":
            $setup = new WposPosSetup($data);
            $result = $setup->addLocation($result);
            break;
        case "locations/edit":
            $setup = new WposPosSetup($data);
            $result = $setup->updateLocationName($result);
            break;
        case "locations/delete":
            $setup = new WposPosSetup($data);
            $result = $setup->deleteLocation($result);
            break;
        case "locations/disable":
            $setup = new WposPosSetup($data);
            $result = $setup->setLocationDisabled($result);
            break;
            // SALES (All transactions)
        // SALES (All transactions)
        case "sales/delete":
            $aSaleMdl = new WposTransactions($data);
            $result = $aSaleMdl->deleteSale($result);
            break;
        case "sales/deletevoid":
            $aSaleMdl = new WposTransactions($data);
            $result = $aSaleMdl->removeVoidRecord($result);
            break;
        case "sales/adminvoid":
            // the admin add void method, only requires sale id and reason
            $aSaleMdl = new WposTransactions($data);
            $result = $aSaleMdl->voidSale($result);
            break;
            // INVOICES
        // INVOICES
        case "invoices/get":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->getInvoices($result);
            break;
        case "invoices/add":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->createInvoice($result);
            break;
        case "invoices/edit":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->updateInvoice($result);
            break;
        case "invoices/delete":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->removeInvoice($result);
            break;
        case "invoices/items/add":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->addItem($result);
            break;
        case "invoices/items/edit":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->updateItem($result);
            break;
        case "invoices/items/delete":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->removeItem($result);
            break;
        case "invoices/payments/add":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->addPayment($result);
            break;
        case "invoices/payments/edit":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->updatePayment($result);
            break;
        case "invoices/payments/delete":
            $invMdl = new WposInvoices($data);
            $result = $invMdl->removePayment($result);
            break;
        case "invoices/history/get":
            $invMdl = new WposTransactions($data);
            $result = $invMdl->getTransactionHistory($result);
            break;
        case "invoices/generate":
            $invMdl = new WposTransactions(null, $_REQUEST['id'], false);
            $invMdl->generateInvoice();
            break;
        case "invoices/email":
            $invMdl = new WposTransactions($data);
            $result = $invMdl->emailInvoice($result);
            break;
            // STATS
        // STATS
        case "stats/general":
            // general overview stats
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getOverviewStats($result);
            break;
        case "stats/takings":
            // account takings stats, categorized by payment method
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getCountTakingsStats($result);
            break;
        case "stats/itemselling":
            // whats selling, grouped by stored items
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getWhatsSellingStats($result);
            break;
        case "stats/supplyselling":
            // whats selling, grouped by suppliers
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getWhatsSellingStats($result, true);
            break;
        case "stats/stock":
            // current stock levels
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getStockLevels($result);
            break;
        case "stats/devices":
            // whats selling, grouped by stored items
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getDeviceBreakdownStats($result);
            break;
        case "stats/locations":
            // whats selling, grouped by stored items
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getDeviceBreakdownStats($result, 'location');
            break;
        case "stats/users":
            // whats selling, grouped by stored items
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getDeviceBreakdownStats($result, 'user');
            break;
        case "stats/tax":
            // whats selling, grouped by stored items
            $statsMdl = new WposAdminStats($data);
            $result = $statsMdl->getTaxStats($result);
            break;
            // GRAPH
        // GRAPH
        case "graph/general":
            // like the general stats, but in graph form/time.
            $graphMdl = new WposAdminGraph($data);
            $result = $graphMdl->getOverviewGraph($result);
            break;
        case "graph/takings":
            // like the general stats, but in graph form/time.
            $graphMdl = new WposAdminGraph($data);
            $result = $graphMdl->getMethodGraph($result);
            break;
        case "graph/devices":
            // like the general stats, but in graph form/time.
            $graphMdl = new WposAdminGraph($data);
            $result = $graphMdl->getDeviceGraph($result);
            break;
        case "graph/locations":
            // like the general stats, but in graph form/time.
            $graphMdl = new WposAdminGraph($data);
            $result = $graphMdl->getLocationGraph($result);
            break;
            // Admin/Global Config
        // Admin/Global Config
        case "settings/get":
            $configMdl = new WposAdminSettings();
            $configMdl->setName($data->name);
            $result = $configMdl->getSettings($result);
            break;
        case "settings/general/get":
            $configMdl = new WposAdminSettings();
            $configMdl->setName("general");
            $result = $configMdl->getSettings($result);
            break;
        case "settings/pos/get":
            $configMdl = new WposAdminSettings();
            $configMdl->setName("pos");
            $result = $configMdl->getSettings($result);
            break;
        case "settings/invoice/get":
            $configMdl = new WposAdminSettings();
            $configMdl->setName("invoice");
            $result = $configMdl->getSettings($result);
            break;
        case "settings/set":
            $configMdl = new WposAdminSettings($data);
            $result = $configMdl->saveSettings($result);
            break;
        case "settings/general/set":
            $configMdl = new WposAdminSettings($data);
            $configMdl->setName("general");
            $result = $configMdl->saveSettings($result);
            break;
        case "settings/pos/set":
            $configMdl = new WposAdminSettings($data);
            $configMdl->setName("pos");
            $result = $configMdl->saveSettings($result);
            break;
        case "settings/invoice/set":
            $configMdl = new WposAdminSettings($data);
            $configMdl->setName("invoice");
            $result = $configMdl->saveSettings($result);
            break;
        case "settings/google/authinit":
            GoogleIntegration::initGoogleAuth();
            break;
        case "settings/google/authremove":
            GoogleIntegration::removeGoogleAuth();
            break;
        case "settings/xero/oauthinit":
            XeroIntegration::initXeroAuth();
            break;
        case "settings/xero/oauthcallback":
            XeroIntegration::processCallbackAuthCode();
            break;
        case "settings/xero/oauthremove":
            XeroIntegration::removeXeroAuth();
            break;
        case "settings/xero/configvalues":
            $result = XeroIntegration::getXeroConfigValues($result);
            break;
        case "settings/xero/export":
            $result = XeroIntegration::exportXeroSales($data->stime, $data->etime);
            break;
        case "node/status":
            $Sserver = new WposSocketControl();
            $result = $Sserver->isServerRunning($result);
            break;
        case "node/start":
            $Sserver = new WposSocketControl();
            $result = $Sserver->startSocketServer($result);
            break;
        case "node/stop":
            $Sserver = new WposSocketControl();
            $result = $Sserver->stopSocketServer($result);
            break;
        case "node/restart":
            $Sserver = new WposSocketControl();
            $result = $Sserver->restartSocketServer($result);
            break;
        case "db/backup":
            $util = new WposAdminUtilities();
            $util->backUpDatabase();
            break;
        case "logs/list":
            $result['data'] = Logger::ls();
            break;
        case "logs/read":
            $result['data'] = Logger::read($data->filename);
            break;
        case "file/upload":
            if (isset($_FILES['file'])) {
                $uploaddir = 'docs';
                $newpath = $uploaddir . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
                if (move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . $_SERVER['APP_ROOT'] . $newpath) !== false) {
                    $result['data'] = ["path" => "/" . $newpath];
                } else {
                    $result['error'] = "There was an error uploading the file " . $newpath;
                }
            } else {
                $result['error'] = "No file selected";
            }
            break;
            // device message
        // device message
        case "message/send":
            $socket = new WposSocketIO();
            if ($data->device === null) {
                if (($error = $socket->sendBroadcastMessage($data->message)) !== true) {
                    $result['error'] = $error;
                }
            } else {
                $devid = intval($data->device);
                $devices = new stdClass();
                $devices->{$devid} = $devid;
                if (($error = $socket->sendMessageToDevices($devices, $data->message)) !== true) {
                    $result['error'] = $error;
                }
            }
            break;
            // device reset
        // device reset
        case "device/reset":
            $socket = new WposSocketIO();
            if ($data->device === null) {
                if (($error = $socket->sendResetCommand()) !== true) {
                    $result['error'] = $error;
                }
            } else {
                $devid = intval($data->device);
                $devices = new stdClass();
                $devices->{$devid} = $devid;
                if (($error = $socket->sendResetCommand($devices)) !== true) {
                    $result['error'] = $error;
                }
            }
            break;
        default:
            $result["error"] = "Action not defined: " . $action;
            break;
    }
    return $result;
}
コード例 #9
0
ファイル: invoice.php プロジェクト: razmir/wallacepos
				<td colspan="4" align="right">
					<?php 
echo 'Amount Paid: ';
?>
				</td>
				<td align="right">
					<?php 
echo WposAdminUtilities::currencyFormat($settings->curformat, $invoice->total - $invoice->balance);
?>
				</td>
			</tr>
			<tr>
				<td colspan="4" align="right">
					<?php 
echo 'Total Due: ';
?>
				</td>
				<td align="right">
					<?php 
echo WposAdminUtilities::currencyFormat($settings->curformat, $invoice->balance);
?>
				</td>
			</tr>
		</table>
        <div style="margin-top: 20px;">
            <?php 
echo $settings->payinst;
?>
        </div>
	</body>
</html>
コード例 #10
0
 /**
  * Get tax statistics from the current range
  * @param $result
  * @return mixed
  */
 public function getTaxStats($result)
 {
     $stats = [];
     $itemsMdl = new SaleItemsModel();
     // check if params set, if not set defaults
     $stime = isset($this->data->stime) ? $this->data->stime : strtotime('-1 week') * 1000;
     $etime = isset($this->data->etime) ? $this->data->etime : time() * 1000;
     if (is_array($saleitems = $itemsMdl->getTotalsRange($stime, $etime, true, $this->data->type))) {
         $taxMdl = new TaxItemsModel();
         $taxdata = $taxMdl->get();
         $taxes = [];
         foreach ($taxdata as $value) {
             $taxes[$value['id']] = (object) $value;
         }
         foreach ($saleitems as $saleitem) {
             $itemtax = json_decode($saleitem['tax']);
             if ($itemtax->total == 0) {
                 if (!array_key_exists(-1, $stats)) {
                     $stats[-1] = new stdClass();
                     $stats[-1]->refs = [];
                     $stats[-1]->name = "Untaxed";
                     $stats[-1]->qtyitems = 0;
                     $stats[-1]->saletotal = 0;
                     $stats[-1]->refundtotal = 0;
                     $stats[-1]->saletax = 0;
                     $stats[-1]->refundtax = 0;
                 }
                 if (!in_array($saleitem['ref'], $stats[-1]->refs)) {
                     $stats[-1]->refs[] = $saleitem['ref'];
                 }
                 $stats[-1]->qtyitems += $saleitem['qty'];
                 $stats[-1]->saletotal += $saleitem['itemtotal'];
                 $stats[-1]->refundtotal += $saleitem['refundtotal'];
             } else {
                 // subtotal excludes tax, factors in discount
                 $discountedtax = $saleitem['discount'] > 0 ? round($itemtax->total - $itemtax->total * ($saleitem['discount'] / 100), 2) : $itemtax->total;
                 //echo($discountedtax);
                 $itemsubtotal = $saleitem['itemtotal'] - $discountedtax;
                 $refundsubtotal = $saleitem['refundtotal'] - round($discountedtax / $saleitem['qty'] * $saleitem['refundqty'], 2);
                 foreach ($itemtax->values as $key => $value) {
                     if (!array_key_exists($key, $stats)) {
                         $stats[$key] = new stdClass();
                         $stats[$key]->refs = [];
                         $stats[$key]->name = isset($taxes[$key]) ? $taxes[$key]->name : "Unknown";
                         $stats[$key]->qtyitems = 0;
                         $stats[$key]->saletotal = 0;
                         $stats[$key]->refundtotal = 0;
                         //$stats[$key]->saletax = 0;
                         //$stats[$key]->refundtax = 0;
                     }
                     if (!in_array($saleitem['ref'], $stats[$key]->refs)) {
                         $stats[$key]->refs[] = $saleitem['ref'];
                     }
                     $stats[$key]->qtyitems += $saleitem['qty'];
                     $stats[$key]->saletotal += $itemsubtotal;
                     // subtotal excludes tax, factors in discount
                     $stats[$key]->refundtotal += $refundsubtotal;
                     //$stats[$key]->saletax += $saleitem['discount']>0 ? round($value - ($value*($saleitem['discount']/100)), 2) : $value;
                     // $stats[$key]->refundtax += $saleitem['discount']>0 ? (round($value/($saleitem['discount']/100), 2)/$saleitem['qty'])*$saleitem['refundqty']: ($value/$saleitem['qty'])*$saleitem['refundqty'];
                 }
             }
         }
         foreach ($stats as $key => $value) {
             $taxitems = WposAdminUtilities::getTaxTable()['items'];
             $stats[$key]->saletax = round($taxitems[$key]['multiplier'] * $stats[$key]->saletotal, 2);
             $stats[$key]->refundtax = round($taxitems[$key]['multiplier'] * $stats[$key]->refundtotal, 2);
             $stats[$key]->balance = number_format($stats[$key]->saletax - $stats[$key]->refundtax, 2);
         }
         // Get cash rounding total
         $roundtotals = $itemsMdl->getRoundingTotal($stime, $etime);
         if ($roundtotals !== false) {
             $stats[0] = new stdClass();
             $stats[0]->refs = $roundtotals[0]['refs'];
             $stats[0]->name = "Cash Rounding";
             $stats[0]->qty = $roundtotals[0]['num'];
             $stats[0]->total = $roundtotals[0]['total'];
         } else {
             $result['error'] = $itemsMdl->errorInfo;
         }
     } else {
         $result['error'] = $itemsMdl->errorInfo;
     }
     $result['data'] = $stats;
     return $result;
 }
コード例 #11
0
ファイル: invoice.php プロジェクト: cosmospham/wallacepos
?>
<br />
						<?php 
echo 'Invoice Date';
?>
:&nbsp;&nbsp;
						<?php 
echo WposAdminUtilities::getDateFromTimeStamp($invoice->processdt, $settings->dateformat, false);
?>
<br />
						<?php 
echo 'Due Date';
?>
:&nbsp;&nbsp;
						<?php 
echo WposAdminUtilities::getDateFromTimeStamp($invoice->duedt, $settings->dateformat, false);
?>
					</p>
				</td>
			</tr>
		</table>
		<p>
			<?php 
echo $customer->name;
?>
<br />
			<?php 
echo $customer->address;
?>
<br />
            <?php