Пример #1
0
 /**
   Delete item(s) from scale
   @param $items [string] four digit PLU 
     or [array] of [string] 4 digit PLUs
 */
 public static function deleteItemsFromScales($items, $scales = array())
 {
     $config = \FannieConfig::factory();
     if (!is_array($items)) {
         $items = array($items);
     }
     $selected_scales = $scales;
     if (!is_array($scales) || count($selected_scales) == 0) {
         $selected_scales = $config->get('SCALES');
     }
     $file_prefix = ServiceScaleLib::sessionKey();
     $output_dir = $config->get('DGW_DIRECTORY');
     if ($output_dir == '') {
         return false;
     }
     $counter = 0;
     foreach ($selected_scales as $scale) {
         $file_name = sys_get_temp_dir() . '/' . $file_prefix . '_deleteItem_' . $counter . '.csv';
         $et_name = sys_get_temp_dir() . '/' . $file_prefix . '_deleteText_' . $counter . '.csv';
         $fp = fopen($file_name, 'w');
         $fp2 = fopen($et_name, 'w');
         fwrite($fp, "Record Type,Task Department,Task Destination,Task Destination Device,Task Destination Type\r\n");
         fwrite($fp, "ExecuteOneTask,{$scale['dept']},{$scale['host']},{$scale['type']},SCALE\r\n");
         fwrite($fp, "Record Type,PLU Number\r\n");
         fwrite($fp2, "Record Type,Task Department,Task Destination,Task Destination Device,Task Destination Type\r\n");
         fwrite($fp2, "ExecuteOneTask,{$scale['dept']},{$scale['host']},{$scale['type']},SCALE\r\n");
         fwrite($fp2, "Record Type,Expanded Text Number\r\n");
         foreach ($items as $plu) {
             if (strlen($plu) !== 4) {
                 // might be a UPC
                 $upc = str_pad($plu, 13, '0', STR_PAD_LEFT);
                 if (substr($upc, 0, 3) != '002') {
                     // not a valid UPC either
                     continue;
                 }
                 preg_match("/002(\\d\\d\\d\\d)0/", $upc, $matches);
                 $plu = $matches[1];
             }
             fwrite($fp, "DeleteOneItem,{$plu}\r\n");
             fwrite($fp2, "DeleteOneExpandedText,{$plu}\r\n");
         }
         fclose($fp);
         fclose($fp2);
         // move to DGW dir
         if (!rename($file_name, $output_dir . '/' . basename($file_name))) {
             unlink($file_name);
         }
         if (!rename($et_name, $output_dir . '/' . basename($et_name))) {
             unlink($et_name);
         }
         $counter++;
     }
 }
Пример #2
0
 /**
   Delete item(s) from scale
   @param $items [string] four digit PLU 
     or [array] of [string] 4 digit PLUs
 */
 public static function deleteItemsFromScales($items, $scales = array())
 {
     $config = \FannieConfig::factory();
     if (!is_array($items)) {
         $items = array($items);
     }
     $file_prefix = ServiceScaleLib::sessionKey();
     $output_dir = $config->get('EPLUM_DIRECTORY');
     if ($output_dir == '') {
         return false;
     }
     $selected_scales = $scales;
     if (!is_array($scales) || count($selected_scales) == 0) {
         $selected_scales = $config->get('SCALES');
     }
     $scale_model = new \ServiceScalesModel(\FannieDB::get($config->get('OP_DB')));
     $counter = 0;
     foreach ($selected_scales as $scale) {
         $file_name = sys_get_temp_dir() . '/' . $file_prefix . '_deleteItem_' . $counter . '.dat';
         $fptr = fopen($file_name, 'w');
         foreach ($items as $plu) {
             if (strlen($plu) !== 4) {
                 // might be a UPC
                 $upc = str_pad($plu, 13, '0', STR_PAD_LEFT);
                 if (substr($upc, 0, 3) != '002') {
                     // not a valid UPC either
                     continue;
                 }
                 preg_match("/002(\\d\\d\\d\\d)0/", $upc, $matches);
                 $plu = $matches[1];
             }
         }
         fclose($fptr);
         // move to DGW dir
         if (!rename($file_name, $output_dir . '/' . basename($file_name))) {
             unlink($file_name);
         }
         $counter++;
     }
 }