Beispiel #1
0
 /**
  * Returns true if a device is associated with the provided locationid
  * @param $id
  * @return bool
  */
 private function isLocationUsed($id)
 {
     $devMdl = new DevicesModel();
     $devs = $devMdl->getLocationDeviceIds(null, $id);
     if (sizeof($devs) > 0) {
         return true;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Broadcast the transaction to admin dash & devices included via config
  * @param $curdeviceid
  * @param bool $updatedsaleflag
  * @param bool $delete
  * @return bool
  */
 private function broadcastSale($curdeviceid, $updatedsaleflag = false, $delete = false)
 {
     $socket = new WposSocketIO();
     $wposConfig = new WposAdminSettings();
     $config = $wposConfig->getSettingsObject("pos");
     $devices = [];
     switch ($config->saledevice) {
         case "device":
             return true;
             // no need to do anything, the device will already get the updated record
         // no need to do anything, the device will already get the updated record
         case "all":
             // get all device id's
             $devMdl = new DevicesModel();
             $devices = $devMdl->getDeviceIds();
             break;
         case "location":
             // get location device id array
             $devMdl = new DevicesModel();
             $devices = $devMdl->getLocationDeviceIds($curdeviceid);
             break;
     }
     // put devices into object, node.js array functions suck
     $dobject = new stdClass();
     foreach ($devices as $value) {
         if ($curdeviceid != $value) {
             // remove the current device from broadcast
             $dobject->{$value} = $value;
         }
     }
     if ($updatedsaleflag == true) {
         $this->jsonobj->isupdate = 1;
     }
     $socket->sendSaleUpdate($dobject, $delete ? $this->jsonobj->ref : $this->jsonobj);
     return true;
 }
Beispiel #3
0
 /**
  * If stime & etime are not set, This function returns sales using the provided devices ID, using POS configuration values.
  *
  * @param $result
  * @return mixed
  */
 public function getSales($result)
 {
     if (!isset($this->data->stime) || !isset($this->data->etime)) {
         // time not set, retrieving POS records, get config.
         $WposConfig = new WposAdminSettings();
         $config = $WposConfig->getSettingsObject("pos");
         // set the sale range based on the config setting
         $etime = time() * 1000;
         $stime = strtotime("-1 " . (isset($config->salerange) ? $config->salerange : "week")) * 1000;
         // determine which devices transactions to include based on config
         if (isset($this->data->deviceid)) {
             switch ($config->saledevice) {
                 case "device":
                     break;
                     // no need to do anything, id already set
                 // no need to do anything, id already set
                 case "all":
                     unset($this->data->deviceid);
                     // unset the device id to get all sales
                     break;
                 case "location":
                     // get location device id array
                     $devMdl = new DevicesModel();
                     $this->data->deviceid = $devMdl->getLocationDeviceIds($this->data->deviceid);
             }
         }
     } else {
         $stime = $this->data->stime;
         $etime = $this->data->etime;
     }
     // Get all transactions within the specified timeframe/devices
     $salesMdl = new SalesModel();
     $dbSales = $salesMdl->getRangeWithRefunds($stime, $etime, isset($this->data->deviceid) ? $this->data->deviceid : null);
     if (is_array($dbSales)) {
         $sales = [];
         foreach ($dbSales as $sale) {
             $sales[$sale['ref']] = json_decode($sale['data'], true);
         }
         $result['data'] = $sales;
     } else {
         if ($dbSales === false) {
             $result['error'] = $salesMdl->errorInfo;
         }
     }
     return $result;
 }