예제 #1
0
 function do_excel_import()
 {
     if (is_on_demo_host()) {
         $msg = lang('items_excel_import_disabled_on_demo');
         echo json_encode(array('success' => false, 'message' => $msg));
         return;
     }
     set_time_limit(0);
     //$this->check_action_permission('add_update');
     $this->db->trans_start();
     $msg = 'do_excel_import';
     $failCodes = array();
     if ($_FILES['file_path']['error'] != UPLOAD_ERR_OK) {
         $msg = lang('suppliers_excel_import_failed');
         echo json_encode(array('success' => false, 'message' => $msg));
         return;
     } else {
         if (($handle = fopen($_FILES['file_path']['tmp_name'], "r")) !== FALSE) {
             $objPHPExcel = file_to_obj_php_excel($_FILES['file_path']['tmp_name']);
             $sheet = $objPHPExcel->getActiveSheet();
             $num_rows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
             //Loop through rows, skip header row
             for ($k = 2; $k <= $num_rows; $k++) {
                 $item_id = $sheet->getCellByColumnAndRow(0, $k)->getValue();
                 if (!$item_id) {
                     $item_id = '';
                 }
                 $price = $sheet->getCellByColumnAndRow(1, $k)->getValue();
                 if (!$price) {
                     $price = null;
                 }
                 $quantity = $sheet->getCellByColumnAndRow(2, $k)->getValue();
                 if (!$quantity) {
                     $quantity = 1;
                 }
                 $discount = $sheet->getCellByColumnAndRow(3, $k)->getValue();
                 if (!$discount) {
                     $discount = 0;
                 }
                 if ($this->sale_lib->is_valid_item_kit($item_id)) {
                     if (!$this->sale_lib->add_item_kit($item_id, $quantity, $discount, $price)) {
                         $this->sale_lib->empty_cart();
                         echo json_encode(array('success' => false, 'message' => lang('batch_sales_error')));
                         return;
                     }
                 } elseif (!$this->sale_lib->add_item($item_id, $quantity, $discount, $price)) {
                     $this->sale_lib->empty_cart();
                     echo json_encode(array('success' => false, 'message' => lang('batch_sales_error')));
                     return;
                 }
             }
         } else {
             echo json_encode(array('success' => false, 'message' => lang('common_upload_file_not_supported_format')));
             return;
         }
     }
     $this->db->trans_complete();
     echo json_encode(array('success' => true, 'message' => lang('sales_import_successfull')));
 }
예제 #2
0
 function do_excel_import()
 {
     if (is_on_demo_host()) {
         $msg = lang('items_excel_import_disabled_on_demo');
         echo json_encode(array('success' => false, 'message' => $msg));
         return;
     }
     set_time_limit(0);
     $this->check_action_permission('add_update');
     $this->db->trans_start();
     $msg = 'do_excel_import';
     $failCodes = array();
     if ($_FILES['file_path']['error'] != UPLOAD_ERR_OK) {
         $msg = lang('items_excel_import_failed');
         echo json_encode(array('success' => false, 'message' => $msg));
         return;
     } else {
         if (($handle = fopen($_FILES['file_path']['tmp_name'], "r")) !== FALSE) {
             $objPHPExcel = file_to_obj_php_excel($_FILES['file_path']['tmp_name']);
             $sheet = $objPHPExcel->getActiveSheet();
             $num_rows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
             //Loop through rows, skip header row
             for ($k = 2; $k <= $num_rows; $k++) {
                 $first_name = $sheet->getCellByColumnAndRow(0, $k)->getValue();
                 if (!$first_name) {
                     $first_name = '';
                 }
                 $last_name = $sheet->getCellByColumnAndRow(1, $k)->getValue();
                 if (!$last_name) {
                     $last_name = '';
                 }
                 $gender = $sheet->getCellByColumnAndRow(2, $k)->getValue();
                 if (!$gender) {
                     $gender = '';
                 }
                 $dob = $sheet->getCellByColumnAndRow(3, $k)->getValue();
                 if (!$dob) {
                     $dob = '';
                 }
                 $idt = $sheet->getCellByColumnAndRow(4, $k)->getValue();
                 if (!$idt) {
                     $idt = '';
                 }
                 $age = $sheet->getCellByColumnAndRow(5, $k)->getValue();
                 if (!$age) {
                     $age = '';
                 }
                 $email = $sheet->getCellByColumnAndRow(6, $k)->getValue();
                 if (!$email) {
                     $email = '';
                 }
                 $phone_number = $sheet->getCellByColumnAndRow(7, $k)->getValue();
                 if (!$phone_number) {
                     $phone_number = '';
                 }
                 $address_1 = $sheet->getCellByColumnAndRow(8, $k)->getValue();
                 if (!$address_1) {
                     $address_1 = '';
                 }
                 //					$address_2 = $sheet->getCellByColumnAndRow(5, $k)->getValue();
                 //					if (!$address_2)
                 //					{
                 //						$address_2 = '';
                 //					}
                 //
                 //					$city = $sheet->getCellByColumnAndRow(6, $k)->getValue();
                 //					if (!$city)
                 //					{
                 //						$city = '';
                 //					}
                 //
                 //					$state = $sheet->getCellByColumnAndRow(7, $k)->getValue();
                 //					if (!$state)
                 //					{
                 //						$state = '';
                 //					}
                 //
                 //					$zip = $sheet->getCellByColumnAndRow(8, $k)->getValue();
                 //					if (!$zip)
                 //					{
                 //						$zip = '';
                 //					}
                 //					$country = $sheet->getCellByColumnAndRow(9, $k)->getValue();
                 //					if (!$country)
                 //					{
                 //						$country = '';
                 //					}
                 $comments = $sheet->getCellByColumnAndRow(9, $k)->getValue();
                 if (!$comments) {
                     $comments = '';
                 }
                 //					$account_number = $sheet->getCellByColumnAndRow(11, $k)->getValue();
                 //					if (!$account_number)
                 //					{
                 //						$account_number = NULL;
                 //					}
                 //
                 //					$taxable = $sheet->getCellByColumnAndRow(12, $k)->getValue();
                 //
                 //					$company_name = $sheet->getCellByColumnAndRow(13, $k)->getValue();
                 //					if (!$company_name)
                 //					{
                 //						$company_name = '';
                 //					}
                 $person_id = $sheet->getCellByColumnAndRow(10, $k)->getValue();
                 $person_data = array('first_name' => $first_name, 'last_name' => $last_name, 'age' => $age, 'gender' => $gender, 'dob' => $dob, 'identity_no' => $idt, 'email' => $email, 'phone_number' => $phone_number, 'address_1' => $address_1, 'comments' => $comments);
                 $customer_data = array('account_number' => '', 'taxable' => 0, 'company_name' => '');
                 if (!$this->Customer->save($person_data, $customer_data, $person_id ? $person_id : FALSE)) {
                     echo json_encode(array('success' => false, 'message' => lang('customers_duplicate_account_id')));
                     return;
                 }
             }
         } else {
             echo json_encode(array('success' => false, 'message' => lang('common_upload_file_not_supported_format')));
             return;
         }
     }
     $this->db->trans_complete();
     echo json_encode(array('success' => true, 'message' => lang('customers_import_successfull')));
 }
예제 #3
0
 function do_excel_import()
 {
     if (is_on_demo_host()) {
         $msg = lang('items_excel_import_disabled_on_demo');
         echo json_encode(array('success' => false, 'message' => $msg));
         return;
     }
     set_time_limit(0);
     $this->check_action_permission('add_update');
     $this->db->trans_start();
     $msg = 'do_excel_import';
     $failCodes = array();
     if ($_FILES['file_path']['error'] != UPLOAD_ERR_OK) {
         $msg = lang('items_excel_import_failed');
         echo json_encode(array('success' => false, 'message' => $msg));
         return;
     } else {
         if (($handle = fopen($_FILES['file_path']['tmp_name'], "r")) !== FALSE) {
             $objPHPExcel = file_to_obj_php_excel($_FILES['file_path']['tmp_name']);
             $sheet = $objPHPExcel->getActiveSheet();
             $num_rows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
             $price_tiers_count = $this->Tier->count_all();
             //Loop through rows, skip header row
             for ($k = 2; $k <= $num_rows; $k++) {
                 $name = $sheet->getCellByColumnAndRow(2, $k)->getValue();
                 if (!$name) {
                     $name = '';
                 }
                 $description = $sheet->getCellByColumnAndRow(11 + $price_tiers_count, $k)->getValue();
                 if (!$description) {
                     $description = '';
                 }
                 $category = $sheet->getCellByColumnAndRow(3, $k)->getValue();
                 if (!$category) {
                     $category = '';
                 }
                 $cost_price = $sheet->getCellByColumnAndRow(5, $k)->getValue();
                 if ($cost_price == NULL) {
                     $cost_price = 0;
                 }
                 $unit_price = $sheet->getCellByColumnAndRow(6, $k)->getValue();
                 if ($unit_price == NULL) {
                     $unit_price = 0;
                 }
                 $tax_included = $sheet->getCellByColumnAndRow(7 + $price_tiers_count, $k)->getValue();
                 $tax_included = ($tax_included != null && $tax_included != '' and $tax_included != '0' and strtolower($tax_included) != 'n') ? '1' : '0';
                 $is_service = $sheet->getCellByColumnAndRow(8 + $price_tiers_count, $k)->getValue();
                 $is_service = ($is_service != null && $is_service != '' and $is_service != '0' and strtolower($is_service) != 'n') ? '1' : '0';
                 $quantity = $sheet->getCellByColumnAndRow(9 + $price_tiers_count, $k)->getValue();
                 $reorder_level = $sheet->getCellByColumnAndRow(10 + $price_tiers_count, $k)->getValue();
                 $supplier_id = $sheet->getCellByColumnAndRow(4, $k)->getValue();
                 $supplier_id = $this->Supplier->exists($supplier_id) ? $supplier_id : $this->Supplier->find_supplier_id($supplier_id);
                 $allow_alt_description = $sheet->getCellByColumnAndRow(12 + $price_tiers_count, $k)->getValue();
                 $allow_alt_description = ($allow_alt_description != null && $allow_alt_description != '' and $allow_alt_description != '0' and strtolower($allow_alt_description) != 'n') ? '1' : '0';
                 $is_serialized = $sheet->getCellByColumnAndRow(13 + $price_tiers_count, $k)->getValue();
                 $is_serialized = ($is_serialized != null && $is_serialized != '' and $is_serialized != '0' and strtolower($is_serialized) != 'n') ? '1' : '0';
                 $size = $sheet->getCellByColumnAndRow(14 + $price_tiers_count, $k)->getValue();
                 if (!$size) {
                     $size = '';
                 }
                 $item_number = $sheet->getCellByColumnAndRow(0, $k)->getValue();
                 $product_id = $sheet->getCellByColumnAndRow(1, $k)->getValue();
                 $item_id = $sheet->getCellByColumnAndRow(16 + $price_tiers_count, $k)->getValue();
                 if (!$item_id) {
                     $item_id = FALSE;
                 }
                 $item_data = array('name' => $name, 'description' => $description, 'category' => $category, 'cost_price' => $cost_price, 'unit_price' => $unit_price, 'tax_included' => $tax_included, 'is_service' => $is_service, 'reorder_level' => $reorder_level, 'supplier_id' => $supplier_id, 'allow_alt_description' => $allow_alt_description, 'is_serialized' => $is_serialized, 'size' => $size);
                 if ($item_number != "") {
                     $item_data['item_number'] = $item_number;
                 } else {
                     $item_data['item_number'] = NULL;
                 }
                 if ($product_id != "") {
                     $item_data['product_id'] = $product_id;
                 } else {
                     $item_data['product_id'] = NULL;
                 }
                 $commission = $sheet->getCellByColumnAndRow(15 + $price_tiers_count, $k)->getValue();
                 if ($commission) {
                     if (strpos($commission, '%') === FALSE) {
                         $item_data['commission_fixed'] = (double) $commission;
                         $item_data['commission_percent'] = NULL;
                     } else {
                         $item_data['commission_percent'] = (double) $commission;
                         $item_data['commission_fixed'] = NULL;
                     }
                 } else {
                     $item_data['commission_percent'] = NULL;
                     $item_data['commission_fixed'] = NULL;
                 }
                 if ($this->Item->save($item_data, $item_id)) {
                     $item_unit_price_col_index = 6;
                     $counter = 0;
                     //Save price tiers
                     foreach ($this->Tier->get_all()->result() as $tier) {
                         $tier_id = $tier->id;
                         $tier_data = array('tier_id' => $tier_id);
                         $tier_data['item_id'] = isset($item_data['item_id']) ? $item_data['item_id'] : $item_id;
                         $tier_value = $sheet->getCellByColumnAndRow($item_unit_price_col_index + ($counter + 1), $k)->getValue();
                         if ($tier_value) {
                             if (strpos($tier_value, '%') === FALSE) {
                                 $tier_data['unit_price'] = $tier_value;
                                 $tier_data['percent_off'] = NULL;
                             } else {
                                 $tier_data['percent_off'] = (int) $tier_value;
                                 $tier_data['unit_price'] = NULL;
                             }
                             $this->Item->save_item_tiers($tier_data, isset($item_data['item_id']) ? $item_data['item_id'] : $item_id);
                         } else {
                             $this->Item->delete_tier_price($tier_id, isset($item_data['item_id']) ? $item_data['item_id'] : $item_id);
                         }
                         $counter++;
                     }
                     $item_location_before_save = $this->Item_location->get_info($item_id, $this->Employee->get_logged_in_employee_current_location_id());
                     $this->Item_location->save_quantity($quantity != null ? $quantity : NULL, isset($item_data['item_id']) ? $item_data['item_id'] : $item_id);
                     $employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
                     $emp_info = $this->Employee->get_info($employee_id);
                     $comment = lang('items_csv_import');
                     //Only log inventory if quantity changes
                     if (!$item_data['is_service'] && $quantity != $item_location_before_save->quantity) {
                         $inv_data = array('trans_date' => date('Y-m-d H:i:s'), 'trans_items' => isset($item_data['item_id']) ? $item_data['item_id'] : $item_id, 'trans_user' => $employee_id, 'trans_comment' => $comment, 'trans_inventory' => $quantity - $item_location_before_save->quantity, 'location_id' => $this->Employee->get_logged_in_employee_current_location_id());
                         $this->Inventory->insert($inv_data);
                     }
                 } else {
                     echo json_encode(array('success' => false, 'message' => lang('items_duplicate_item_ids')));
                     return;
                 }
             }
         } else {
             echo json_encode(array('success' => false, 'message' => lang('common_upload_file_not_supported_format')));
             return;
         }
     }
     $this->db->trans_complete();
     echo json_encode(array('success' => true, 'message' => lang('items_import_successful')));
 }