function getCabinetInstallation()
 {
     set_time_limit(0);
     $this->autoRender = false;
     $sql = "SELECT * FROM  install_tasks";
     $datas = $this->Cabinet->query($sql);
     App::uses("InventoryLookup", "Inventory.Model");
     foreach ($datas as $data) {
         $installation['InventoryLookup']['name'] = $data['install_tasks']['description'];
         $installation['InventoryLookup']['lookup_type'] = "installation_type";
         $installation['InventoryLookup']['price'] = $data['install_tasks']['amount'];
         $installation['InventoryLookup']['price_unit'] = $data['install_tasks']['unit'];
         $installation['InventoryLookup']['value'] = $data['install_tasks']['description'];
         $InventoryLookup_model = new InventoryLookup();
         if (!$InventoryLookup_model->save($installation)) {
             pr($InventoryLookup_model->validationErrors);
         }
     }
 }
 function InventoryLookupValue2Name($value)
 {
     App::uses("InventoryLookup", "Inventory.Model");
     $itemDepartment = new InventoryLookup();
     $found = $itemDepartment->find("first", array("fields" => array("id", "name"), 'conditions' => array('InventoryLookup.value' => $value)));
     return isset($found['InventoryLookup']['name']) ? $found['InventoryLookup']['name'] : null;
 }
 function getgruopItemNumber($id)
 {
     $this->autoRender = false;
     App::import('Model', 'Inventory.InventoryLookup');
     $inventorylookup = new InventoryLookup();
     $number = $inventorylookup->find("first", array("conditions" => array("InventoryLookup.id" => $id)));
     $items = $this->Item->find('first', array('limit' => 1, 'order' => array('Item.id DESC')));
     $item_id = $items['Item']['id'] + 1;
     $number['InventoryLookup']['num'] = str_pad($item_id, 4, '0', STR_PAD_LEFT);
     echo json_encode($number);
 }
Ejemplo n.º 4
0
 public function beforeValidate($options = array())
 {
     parent::beforeValidate($options);
     if (!$this->id) {
         if (isset($this->data['Item']['base_item'])) {
             $item = $this->data;
             $this->read(null, $this->data['Item']['base_item']);
             array_merge($this->data['Item'], $item['Item']);
             $item['Item']['item_group'] = $this->data['Item']['item_group'];
             $this->data = $item;
         }
         App::import('Model', 'Inventory.InventoryLookup');
         $inventorylookup = new InventoryLookup();
         $number = $inventorylookup->find("first", array("conditions" => array("InventoryLookup.id" => $this->data['Item']['item_group'])));
         $items = $this->find('first', array('limit' => 1, 'order' => array('Item.id DESC')));
         $item_id = $items['Item']['id'] + 1;
         $number['InventoryLookup']['num'] = str_pad($item_id, 6, '0', STR_PAD_LEFT);
         if ($this->data['Item']['base_item'] != 0) {
             $this->data['Item']['number'] = $number['InventoryLookup']['value'] . $number['InventoryLookup']['num'];
         }
     }
 }
 public function calculateCabinetPriceForBuilder($cabinet_id, $cabinet_color, $material_id, $door_id, $door_color, $drawer_id, $drawer_slide_id, $quantity = 1, $delivery_option = '', $delivery_charge = 0)
 {
     App::import("Model", "Inventory.Cabinet");
     App::uses("Material", "Inventory.Model");
     App::uses("Door", "Inventory.Model");
     App::uses("Color", "Inventory.Model");
     App::import("Model", "Inventory.Item");
     App::import("Model", "Inventory.CabinetsItem");
     App::import("Model", "Inventory.InventoryLookup");
     $cabinet_id = Sanitize::escape($cabinet_id);
     $material_id = Sanitize::escape($material_id);
     $door_id = Sanitize::escape($door_id);
     $door_color = Sanitize::escape($door_color);
     $cabinet_color = Sanitize::escape($cabinet_color);
     $drawer_id = Sanitize::escape($drawer_id);
     $drawer_slide_id = Sanitize::escape($drawer_slide_id);
     $debug_calculation = '';
     $cabinets_items_model = new CabinetsItem();
     $cabinets_items_model->recursive = 1;
     $cabinets_items = $cabinets_items_model->find('all', array('conditions' => array('cabinet_id' => $cabinet_id, 'accessories' => '0')));
     $cabinets_accessories = $cabinets_items_model->find('all', array('conditions' => array('cabinet_id' => $cabinet_id, 'accessories' => '1')));
     if (!empty($cabinet_id)) {
         $cabinet = new Cabinet();
         $cabinet_detail = $cabinet->find('first', array('conditions' => array('id' => $cabinet_id)));
     }
     // predefined values
     $debug_calculation .= "Blum Up Charge = {$this->bulm_up_charge} <br />";
     $debug_calculation .= "Default Markup Factor = {$this->default_markup} <br />";
     $debug_calculation .= "<br />";
     // calculate cabinet sqft
     $item_model = new Item();
     $cabinet_sqft = $this->calculateCabinetSQFTForBuilder($cabinets_items, $item_model, $material_id);
     $debug_calculation .= "Cabinet SQFT = {$cabinet_sqft} <br />";
     $debug_calculation .= "<br />";
     // calculate cabinet sqft
     $panel_sqft = $this->calculatePanelSQFTForBuilder($cabinets_items);
     $debug_calculation .= "Panel SQFT = {$panel_sqft} <br />";
     $debug_calculation .= "<br />";
     // calculate cabinet sqft
     $box_total = $this->calculateBoxTotalForBuilder($cabinets_items, $door_id, $drawer_id, $drawer_slide_id);
     $debug_calculation .= "<b>Box Total Price = {$box_total} </b><br />";
     $debug_calculation .= "<br />";
     // get door color price
     $door_color_price = 0;
     $door_color_detail = array();
     if (!empty($door_color)) {
         $color = new Color();
         $door_color_detail = $color->find('first', array('conditions' => array('id' => $door_color)));
         if (isset($door_color_detail['ColorSection']) && !empty($door_color_detail['ColorSection']) && is_array($door_color_detail['ColorSection'])) {
             foreach ($door_color_detail['ColorSection'] as $color_section) {
                 if ($color_section['type'] == 'door_material') {
                     $door_color_price = $color_section['price'];
                     break;
                 }
             }
         }
         unset($door_color_detail);
         // clean up
         unset($color);
         // clean up
     }
     // get cabinet color price
     $cabinet_color_price = 0;
     $cabinet_price_color = 0;
     $panel_price_color = 0;
     $cabinet_color_detail = array();
     if (!empty($cabinet_color)) {
         $color = new Color();
         $cabinet_color_detail = $color->find('first', array('conditions' => array('id' => $cabinet_color)));
         if (isset($cabinet_color_detail['ColorSection']) && !empty($cabinet_color_detail['ColorSection']) && is_array($cabinet_color_detail['ColorSection'])) {
             foreach ($cabinet_color_detail['ColorSection'] as $color_section) {
                 //          if ($color_section['type'] == 'cabinet_material') {
                 if ($color_section['type'] == 'cabinate_material') {
                     $cabinet_color_price = $color_section['price'];
                     $cabinet_price_color = $cabinet_color_price * $cabinet_sqft;
                     $debug_calculation .= "Cabinet Color Price = {$cabinet_color_price} <br />";
                     $debug_calculation .= "<b>Cabinet Price (Color) = {$cabinet_price_color} </b><br />";
                     $panel_price_color = $cabinet_color_price * $panel_sqft;
                     $debug_calculation .= "<b>Panel Price (Color) = {$panel_price_color} </b><br />";
                     $debug_calculation .= "<br />";
                     break;
                 }
             }
         }
         unset($cabinet_color_detail);
         // clean up
         unset($color);
         // clean up
     }
     $doors_drawers_price = 0;
     if (!empty($door_id)) {
         $door = new Door();
         $door_detail = $door->find('first', array('conditions' => array('Door.id' => $door_id)));
         $door_cost_markup = $door_detail['Door']['cost_markup_factor'];
         $door_drawers = array();
         $debug_calculation .= "Door/Drawer Cost Markup = {$door_cost_markup} <br />";
         $debug_calculation .= "<br />";
         $door_drawers['top_door'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['top_door_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['top_door_height'];
             $width = (double) $cabinet_detail['Cabinet']['top_door_width'];
             $count = (double) $cabinet_detail['Cabinet']['top_door_count'];
             $price_sqft = (double) $door_detail['Door']['wall_door_price'];
             $price_each = (double) $door_detail['Door']['wall_door_price_each'];
             $label = 'Top Door';
             $door_drawers['top_door'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each);
             $debug_calculation .= "<br />";
         }
         $door_drawers['bottom_door'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['bottom_door_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['bottom_door_height'];
             $width = (double) $cabinet_detail['Cabinet']['bottom_door_width'];
             $count = (double) $cabinet_detail['Cabinet']['bottom_door_count'];
             $price_sqft = (double) $door_detail['Door']['door_price'];
             $price_each = (double) $door_detail['Door']['door_price_each'];
             $label = 'Bottom Door';
             $door_drawers['bottom_door'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each);
             $debug_calculation .= "<br />";
         }
         $door_drawers['top_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['top_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['top_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['top_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['top_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['drawer_price'];
             $price_each = (double) $door_detail['Door']['drawer_price_each'];
             $label = 'Top Drawer Front';
             $door_drawers['top_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         $door_drawers['middle_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['middle_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['middle_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['middle_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['middle_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['lower_drawer_price'];
             $price_each = (double) $door_detail['Door']['lower_drawer_price_each'];
             $label = 'Middle Drawer Front';
             $door_drawers['middle_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         $door_drawers['bottom_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['bottom_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['bottom_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['bottom_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['bottom_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['lower_drawer_price'];
             $price_each = (double) $door_detail['Door']['lower_drawer_price_each'];
             $label = 'Bottom Drawer Front';
             $door_drawers['bottom_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         $door_drawers['dummy_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['dummy_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['dummy_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['dummy_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['dummy_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['drawer_price'];
             $price_each = (double) $door_detail['Door']['drawer_price_each'];
             $label = 'Dummy Drawer Front';
             $door_drawers['dummy_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         //      $debug = var_export($door_drawers, true);
         //      $debug_calculation .= "Door/Drawer Price = {$debug} <br />";
         $doors_drawers_price = $this->sumDoorDrawer($door_drawers);
         $debug_calculation .= "<b>Door/Drawer Price = {$doors_drawers_price} </b><br />";
         $debug_calculation .= "<b>Bulm up Charge Total Price = {$this->bulm_up_charge_total} </b><br />";
         $debug_calculation .= "<br />";
         if ($door_color_price) {
             $debug_calculation .= "Door Color Price = {$door_color_price} <br />";
             $debug_calculation .= "<br />";
             $doors_drawers_price_color = $this->sumDoorDrawerColorForBuilder($debug_calculation, $door_drawers, $door_color_price);
             $doors_drawers_price += $doors_drawers_price_color;
             $debug_calculation .= "<br />";
             $debug_calculation .= "<b>Door/Drawer Price (Color) = {$doors_drawers_price_color} </b><br />";
             $debug_calculation .= "<br />";
         }
         unset($door);
         // clean up
     }
     $inventory_lookup = new InventoryLookup();
     $inventory_lookup->recursive = -1;
     $drawer_departments = array();
     $inventory_lookup_detail = $inventory_lookup->find('all', array('conditions' => array('InventoryLookup.lookup_type' => 'drawer')));
     foreach ($inventory_lookup_detail as $inventory_lookup_row) {
         $departments = $inventory_lookup->SearchCache2Array($inventory_lookup_row['InventoryLookup']['department_id']);
         foreach ($departments as $department) {
             if (isset($drawer_departments[$department])) {
                 $drawer_departments[$department][] = $inventory_lookup_row['InventoryLookup']['id'];
             } else {
                 $drawer_departments[$department] = array($inventory_lookup_row['InventoryLookup']['id']);
             }
         }
     }
     $item = new Item();
     $items_price = 0;
     $discount = 0;
     $items = array();
     if (!empty($cabinet_detail['CabinetsItem'])) {
         foreach ($cabinet_detail['CabinetsItem'] as $cabinet_item) {
             if ($cabinet_item['accessories']) {
                 continue;
             }
             // skip the accessories
             $item_detail = $item->find('first', array('conditions' => array('Item.id' => $cabinet_item['item_id'])));
             if (array_key_exists($item_detail['Item']['item_department_id'], $drawer_departments)) {
                 if (!in_array($drawer_id, $drawer_departments[$item_detail['Item']['item_department_id']])) {
                     continue;
                     // skip the un-selected drawer
                 }
             }
             $item_price = $item_detail['Item']['builder_price'];
             //				$item_price = $item_detail['Item']['price'];
             $ItemMaterialPrice = null;
             if (isset($material_id) && !empty($material_id)) {
                 $ItemMaterialPrice = $this->getItemMaterialPriceForBuilder($item, $cabinet_item['item_id'], $material_id, $debug_calculation);
                 $item_price = $ItemMaterialPrice['item_price'];
             }
             //Discount
             //                if( $delivery_option == '5 – 10 Weeks Delivery' ) {
             //                    $discount = $item_price * $this->default_discount;
             //                    $item_price = $item_price - $discount;
             //                }
             $item_calculated_price = $cabinet_item['item_quantity'] * $item_price;
             $items_price += $item_calculated_price;
             if ($ItemMaterialPrice['sub_item']) {
                 $debug_calculation .= "Cabinet Item ({$ItemMaterialPrice['sub_item']['Item']['item_title']}) Price = {$ItemMaterialPrice['material_data']['Material']['price']} => Quantity = {$cabinet_item['item_quantity']} => Total = {$item_calculated_price} <br />";
             } else {
                 $debug_calculation .= "Cabinet Item ({$item_detail['Item']['item_title']}) Price = {$item_price} => Quantity = {$cabinet_item['item_quantity']} => Total = {$item_calculated_price} <br />";
             }
             //        $items[] = array(
             //            'id' => $item_detail['Item']['id'],
             //            'item_title' => $item_detail['Item']['item_title'],
             //            'price' => $item_price,
             //            'base_price' => $item_detail['Item']['price'],
             //            'quantity' => $cabinet_item['item_quantity'],
             //        );
         }
         $debug_calculation .= "<b>Cabinet Item Price = {$items_price} </b><br />";
         $debug_calculation .= "<br />";
         unset($cabinet_detail);
         // clean up
     }
     $total_price = ($items_price + $cabinet_price_color + $panel_price_color + $doors_drawers_price + $this->bulm_up_charge_total) * $this->default_markup * $quantity;
     $discount_rate = $this->getProductionTime($delivery_option);
     $discount = $total_price * $discount_rate;
     $total_price = $total_price - $discount;
     $debug_calculation .= "<b>Discount = {$discount} </b><br />";
     $debug_calculation .= "<b>Total Price = {$total_price} </b><br />";
     $result = array('items_price' => $items_price, 'doors_price' => $doors_drawers_price, 'cabinet_color_price_color' => $cabinet_price_color, 'total_price' => $total_price, 'debug_calculation' => $debug_calculation, 'conditions' => array('resource_id' => $cabinet_id, 'resource_type' => 'cabinet', 'material_id' => $material_id, 'door_id' => $door_id, 'door_color' => $door_color, 'cabinet_color' => $cabinet_color, 'drawer_slide_id' => $drawer_slide_id, 'drawer_id' => $drawer_id, 'quantity' => $quantity));
     return $result;
 }