Exemplo n.º 1
0
 public function afterSave($created)
 {
     parent::afterSave($created);
     if (isset($this->data['CabinetOrder']['resource_type']) && $this->data['CabinetOrder']['resource_type'] == 'cabinet') {
         App::import('Model', 'Inventory.Cabinet');
         $cabinet_model = new Cabinet();
         $cabinet_model->recursive = 1;
         $cabinet_detail = $cabinet_model->find('first', array('conditions' => array('Cabinet.id' => $this->data['CabinetOrder']['resource_id'])));
         if (!empty($cabinet_detail['CabinetsItem']) && is_array($cabinet_detail['CabinetsItem'])) {
             foreach ($cabinet_detail['CabinetsItem'] as $key => $cabinet_item) {
                 $this->data['CabinetOrderItem'][$key] = array('cabinet_order_id' => $this->data['CabinetOrder']['id'], 'quote_id' => $this->data['CabinetOrder']['quote_id'], 'cabinet_id' => $this->data['CabinetOrder']['resource_id'], 'quantity' => $this->data['CabinetOrder']['quantity'] * $cabinet_item['item_quantity'], 'item_id' => $cabinet_item['item_id'], 'code' => "{$cabinet_item['item_id']}|item", 'type' => 'Cabinet Order');
             }
         }
     }
     if (isset($this->data['CabinetOrderItem'])) {
         // delete CabinetOrderItem
         $this->CabinetOrderItem->deleteAll(array('cabinet_order_id' => $this->id));
         if (is_array($this->data['CabinetOrderItem'])) {
             // save CabinetOrderItem
             //        $cabinetOrderItems = array();
             //        $index = 0;
             //        foreach ($this->data['CabinetOrderItem'] as $cabinetOrderItem) {
             //          if (trim($cabinetOrderItem['quantity']) == '' || trim($cabinetOrderItem['code']) == '') {
             //            continue; // skip if no data
             //          }
             //          $cabinetOrderItems[$index]['cabinet_order_id'] = $this->id;
             //          $cabinetOrderItems[$index]['item_id'] = trim($cabinetOrderItem['item_id']);
             //          $cabinetOrderItems[$index]['cabinet_id'] = trim($cabinetOrderItem['cabinet_id']);
             ////          $cabinetOrderItems[$index]['door_id'] = trim($cabinetOrderItem['door_id']);
             ////          $cabinetOrderItems[$index]['door_information'] = trim($cabinetOrderItem['door_information']);
             ////          $cabinetOrderItems[$index]['open_frame_door'] = trim($cabinetOrderItem['open_frame_door']);
             ////          $cabinetOrderItems[$index]['do_not_drill_door'] = trim($cabinetOrderItem['do_not_drill_door']);
             ////          $cabinetOrderItems[$index]['no_doors'] = trim($cabinetOrderItem['no_doors']);
             //          $cabinetOrderItems[$index]['quantity'] = trim($cabinetOrderItem['quantity']);
             //          $cabinetOrderItems[$index]['code'] = trim($cabinetOrderItem['code']);
             //          $cabinetOrderItems[$index]['type'] = "Cabinet Order";
             //
             //          $index++;
             //        }
             $this->CabinetOrderItem->saveAll($this->data['CabinetOrderItem']);
         }
     }
 }
 public function beforeSave($options = array())
 {
     parent::beforeSave($options);
     $this->data['QuoteReportsSetting']['departments'] = serialize($this->data['QuoteReportsSetting']['departments']);
 }
Exemplo n.º 3
0
 public function afterSave($created)
 {
     parent::afterSave($created);
     //    cake_debug($this->data['Quote']); exit;
     //get source
     App::uses("CabinetOrderItem", "QuoteManager.Model");
     $cabinet_order = new CabinetOrderItem();
     if (isset($this->data['CabinetOrderItem'])) {
         // delete
         //      $cabinet_order->deleteAll(array('CabinetOrderItem.quote_id' => $this->id, 'CabinetOrderItem.type' => $this->data['Quote']['type']));
         //
         //      if (is_array($this->data['CabinetOrderItem'])) {
         // save
         //        $couterTopItems = array();
         //        $index = -1;
         //        foreach ($this->data['CabinetOrderItem'] as $couterTopItem) {
         //          if (trim($couterTopItem['quantity']) == '' || $couterTopItem['quantity'] == 0 || trim($couterTopItem['code']) == '') {
         //            continue; // skip if no data
         //          }
         //          $index++;
         //
         //          $couterTopItems[$index]['quote_id'] = $couterTopItem['quote_id'];
         //          $couterTopItems[$index]['used_in'] = isset($couterTopItem['used_in']) ? trim($couterTopItem['used_in']) : "";
         //          $couterTopItems[$index]['optional_color'] = isset($couterTopItem['optional_color']) ? trim($couterTopItem['optional_color']) : "";
         //          $couterTopItems[$index]['code'] = trim($couterTopItem['code']);
         //          $couterTopItems[$index]['quantity'] = trim($couterTopItem['quantity']);
         //          $couterTopItems[$index]['order_number'] = trim($couterTopItem['order_number']);
         //          $couterTopItems[$index]['type'] = trim($this->data['Quote']['type']);
         //
         //          $itemType = explode('|', $couterTopItems[$index]['code']);
         //          if ($itemType[1] == 'item')
         //            $couterTopItems[$index]['item_id'] = trim($itemType[0]);
         //          elseif ($itemType[1] == 'cabinet')
         //            $couterTopItems[$index]['cabinet_id'] = trim($itemType[0]);
         //          elseif ($itemType[1] == 'door' || $itemType[1] == 'wall_door' || $itemType[1] == 'drawer')
         //            $couterTopItems[$index]['door_id'] = trim($itemType[0]);
         //        }
         //        if ($index >= 0) {
         //          $flag = $cabinet_order->saveAll($couterTopItems);
         //        } else {
         //          return false;
         //        }
         //      }
     } elseif (isset($this->data['QuoteInstallerPaysheet'])) {
         //get source
         $this->QuoteInstallerPaysheet->begin();
         // delete
         $this->QuoteInstallerPaysheet->deleteAll(array('quote_id' => $this->id));
         if (is_array($this->data['QuoteInstallerPaysheet'])) {
             // save
             $couterTopItems = array();
             $index = 0;
             foreach ($this->data['QuoteInstallerPaysheet'] as $couterTopItem) {
                 if (trim($couterTopItem['quantity']) == '' || trim($couterTopItem['task_description']) == '' || trim($couterTopItem['unit']) == '' || trim($couterTopItem['price_each']) == '') {
                     continue;
                     // skip if no data
                 }
                 $couterTopItems[$index]['quote_id'] = $couterTopItem['quote_id'];
                 $couterTopItems[$index]['quantity'] = trim($couterTopItem['quantity']);
                 $couterTopItems[$index]['task_description'] = trim($couterTopItem['task_description']);
                 $couterTopItems[$index]['unit'] = trim($couterTopItem['unit']);
                 $couterTopItems[$index]['price_each'] = trim($couterTopItem['price_each']);
                 $couterTopItems[$index]['total'] = trim($couterTopItem['total']);
                 $index++;
             }
             $this->QuoteInstallerPaysheet->saveAll($couterTopItems);
         }
     } elseif (isset($this->data['QuoteStatus'])) {
         //      debug($this->data['QuoteStatus']); exit;
         $couterTopItems['quote_id'] = $this->id;
         $couterTopItems['user_id'] = trim($this->data['QuoteStatus']['user_id']);
         $couterTopItems['quote_vid'] = trim($this->data['QuoteStatus']['quote_vid']);
         $couterTopItems['status'] = trim($this->data['QuoteStatus']['status']);
         $couterTopItems['status_date'] = trim($this->data['QuoteStatus']['status_date']);
         $couterTopItems['comments'] = trim($this->data['QuoteStatus']['comment']);
         $this->QuoteStatus->save($couterTopItems);
     }
 }