Beispiel #1
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;
 }
 /**
  * Delete sale specified by ID, same as delete transaction but sale is broadcast to pos devices
  * @param $result
  * @return mixed
  */
 public function deleteSale($result)
 {
     $saleMdl = new SalesModel();
     if ($saleMdl->remove($this->data->id) === false) {
         $result["error"] = "Error:" . $saleMdl->errorInfo;
     } else {
         $result['data'] = true;
         // broadcast the sale; supplying the id only indicates deletion
         $socket = new WposSocketIO();
         $socket->sendSaleUpdate(null, $this->data->id);
         // log data
         Logger::write("Sale deleted with id:" . $this->data->id, "SALE");
     }
     return $result;
 }