コード例 #1
0
function processFile($filename)
{
    //extract the filename to get the exact filename on the folder
    $newFile = substr($filename, 3);
    $dirname = substr($filename, 0, 2);
    $fs = new Filesystem();
    if ($fs->exists('../Repo/' . $dirname . '/' . $newFile)) {
        $xml = simplexml_load_file('../Repo/' . $dirname . '/' . $newFile, null, LIBXML_NOCDATA);
        $newXML = json_decode(json_encode($xml), true);
        $data = formulateData($newXML, $dirname);
        //insert data to db
        $po = new PurchaseOrder();
        $po->setFilename($newFile);
        $po->setStore($dirname);
        $po->setCustomerCode($data['customer_code']);
        $po->setDeliveryDate($data['delivery_date']);
        $po->setNumber($data['number']);
        $po->save();
        $po_id = $po->getId();
        //insert all items
        foreach ($data['items'] as $key => $value) {
            $items = new Item();
            $items->setPurchaseOrderId($po_id);
            $items->setUpc($value['upc']);
            $items->setQty($value['qty']);
            $items->setQty($value['discount']);
            $items->save();
        }
        $formulated_data = formulateData($newXML, $dirname);
        $formulated_data['id'] = $po_id;
        //print_r($formulated_data);
        return $formulated_data;
    }
}
コード例 #2
0
function processFile($filename)
{
    //extract the filename to get the exact filename on the folder
    $newFile = substr($filename, 3);
    $dirname = substr($filename, 0, 2);
    $fs = new Filesystem();
    if ($fs->exists('../Repo/' . $dirname . '/' . $newFile)) {
        $xml = simplexml_load_file('../Repo/' . $dirname . '/' . $newFile, null, LIBXML_NOCDATA);
        $newXML = json_decode(json_encode($xml), true);
        $data = formulateData($newXML, $dirname);
        //checks if the record is already processed before
        $hasRecord = PurchaseOrderQuery::create()->filterByNumber($data['number'])->find();
        if ($hasRecord->count() === 0) {
            logMessage("No duplicate data: processFile " . date('m/d/Y h:i:s') . ".\n");
            //log something
            //insert data to db
            $po = new PurchaseOrder();
            $po->setFilename($newFile);
            $po->setStore($dirname);
            $po->setCustomerCode($data['customer_code']);
            $po->setDeliveryDate($data['delivery_date']);
            $po->setNumber($data['number']);
            $po->save();
            $po_id = $po->getId();
            //insert all items
            foreach ($data['items'] as $key => $value) {
                $items = new Item();
                $items->setPurchaseOrderId($po_id);
                $items->setUpc($value['upc']);
                $items->setQty($value['qty']);
                $items->setQty($value['discount']);
                $items->save();
            }
            $formulated_data = formulateData($newXML, $dirname);
            $formulated_data['id'] = $po_id;
            //print_r($formulated_data);
            logMessage("Return data in JSON: processFile " . date('m/d/Y h:i:s') . ".\n");
            //log something
            return $formulated_data;
            print_r($formulated_data);
        } else {
            logMessage("This file(" . $newFile . ") with store(" . $dirname . ") is already processed before: processFile " . date('m/d/Y h:i:s') . ".\n");
            //log something
        }
        print_r($data);
    } else {
        logMessage("Return no such file: processFile " . date('m/d/Y h:i:s') . ".\n");
        //log something
        return "No such file!";
    }
}
コード例 #3
0
 public function quote_approved($id = null)
 {
     $this->autoRender = FALSE;
     App::import('Model', 'QuoteManager.QuoteStatus');
     $QuoteStatus = new QuoteStatus();
     App::import('Model', 'QuoteManager.Quote');
     $Quote = new Quote();
     $Q_model = new Quote();
     $quote['Quote']['id'] = $id;
     $quote['Quote']['status'] = 'Approve';
     $Q_data = $Q_model->find("first", array("conditions" => array("Quote.id" => $id)));
     if (empty($Q_data['Quote']['est_shipping'])) {
         if ($Q_data['Quote']['delivery'] == '4 - 8 Weeks Delivery') {
             $add_days = 56;
             $today = $Q_data['Quote']['quote_created_date'];
             $esd_date = date('d/m/Y', strtotime($today) + 24 * 3600 * $add_days);
         }
         if ($Q_data['Quote']['delivery'] == '5 - 10 Weeks Delivery') {
             $add_days = 70;
             $today = $Q_data['Quote']['quote_created_date'];
             $esd_date = date('d/m/Y', strtotime($today) + 24 * 3600 * $add_days);
         }
         $quote['Quote']['est_shipping'] = $esd_date;
     }
     $Quote->save($quote);
     $quote_status['QuoteStatus']['status'] = 'Approve';
     $quote_status['QuoteStatus']['quote_id'] = $id;
     $quote_info = $Quote->find("first", array("conditions" => array("Quote.id" => $id)));
     $workorder['WorkOrder']['quote_id'] = $quote_info['Quote']['id'];
     $workorder['WorkOrder']['project_id'] = $quote_info['Quote']['project_id'];
     $workorder['WorkOrder']['customer_id'] = $quote_info['Quote']['customer_id'];
     $workorder['WorkOrder']['status'] = 'New';
     $quote_number_explode = explode("-", $quote_info['Quote']['quote_number']);
     $workorder['WorkOrder']['work_order_number'] = $quote_number_explode[0];
     $workorder['WorkOrder']['skid_number'] = $quote_info['Quote']['skid_number'];
     $workorder['WorkOrder']['skid_weight'] = $quote_info['Quote']['skid_weight'];
     App::import("Model", "WorkOrderManager.WorkOrder");
     $wo = new WorkOrder();
     $wo->save($workorder);
     App::import("Model", "PurchaseOrderManager.PurchaseOrder");
     App::import("Model", "PurchaseOrderManager.PurchaseOrderItem");
     App::import("Model", "Inventory.Supplier");
     App::import('Model', 'PurchaseOrderManager.GeneralSetting');
     $supplier = array();
     foreach ($quote_info['CabinetOrderItem'] as $quote_item) {
         $item_info = $this->findQuoteItem($quote_item['item_id']);
         $supplier_required = $this->findQuoteItemDept($item_info['Item']['item_department_id']);
         if ($supplier_required['ItemDepartment']['supplier_required'] == 1) {
             $supplier[$item_info['Item']['supplier_id']][] = $item_info;
         }
     }
     $total_amount = 0;
     foreach ($supplier as $key => $value) {
         if (empty($Q_data['Quote']['est_shipping'])) {
             $est_date_quote = $quote['Quote']['est_shipping'];
         } else {
             $est_date_quote = $quote_info['Quote']['est_shipping'];
         }
         $purchaseorder = new PurchaseOrder();
         $sp_model = new Supplier();
         $sp_data = $sp_model->find("first", array("conditions" => array("Supplier.id" => $id)));
         $general_model = new GeneralSetting();
         $location_data = $general_model->find("first", array("conditions" => array("GeneralSetting.name" => 'Default')));
         $po['supplier_id'] = $key;
         $po['work_order_id'] = $wo->id;
         $po_number = explode("-", $quote_info['Quote']['quote_number']);
         $po['purchase_order_num'] = $po_number[0];
         $po['quote_id'] = $quote_info['Quote']['id'];
         $po['shipment_date'] = $est_date_quote;
         $po['payment_type'] = 'On Account';
         $po['issued_on'] = date('d/m/Y');
         $po['issued_by'] = $this->loginUser['id'];
         $po['term'] = $sp_data['Supplier']['terms'];
         $po['location_name'] = $location_data['GeneralSetting']['name'];
         $po['name_ship_to'] = $location_data['GeneralSetting']['name_address'];
         $po['address'] = $location_data['GeneralSetting']['address'];
         $po['city'] = $location_data['GeneralSetting']['city'];
         $po['province'] = $location_data['GeneralSetting']['province'];
         $po['postal_code'] = $location_data['GeneralSetting']['postal_code'];
         $po['country'] = $location_data['GeneralSetting']['country'];
         foreach ($value as $v) {
             foreach ($quote_info['CabinetOrderItem'] as $req_info) {
                 if ($req_info['item_id'] == $v['Item']['id']) {
                     $quantity = $req_info['quantity'];
                     $total_amount = $total_amount + $quantity * $v['Item']['price'];
                 }
             }
         }
         App::import("Model", "PurchaseOrderManager.GeneralSetting");
         $g_setting = new GeneralSetting();
         $gst_rate = $g_setting->find("first", array("conditions" => array("GeneralSetting.type" => 'gst')));
         $pst_rate = $g_setting->find("first", array("conditions" => array("GeneralSetting.type" => 'pst')));
         $gst_amount = $gst_rate['GeneralSetting']['value'] / 100 * $total_amount;
         $pst_amount = $pst_rate['GeneralSetting']['value'] / 100 * $total_amount;
         $total_amount = $total_amount + $gst_amount + $pst_amount;
         $po['total_amount'] = $total_amount;
         $purchaseorder->save($po);
         $index = 0;
         $purchaseorderitem = new PurchaseOrderItem();
         foreach ($value as $v) {
             foreach ($quote_info['CabinetOrderItem'] as $req_info) {
                 if ($req_info['item_id'] == $v['Item']['id']) {
                     $po_item[$index]['quantity'] = $req_info['quantity'];
                     $po_item[$index]['code'] = $req_info['code'];
                     $po_item[$index]['cabinet_id'] = $req_info['cabinet_id'];
                     $po_item[$index]['door_id'] = $req_info['door_id'];
                 }
             }
             $po_item[$index]['item_id'] = $v['Item']['id'];
             $po_item[$index]['purchase_order_id'] = $purchaseorder->id;
             $index++;
         }
         $purchaseorderitem->saveAll($po_item);
     }
     //		foreach($quote_info['CabinetOrderItem'] as $quote_item){
     //			$purchaseorder = new PurchaseOrder();
     //			$item_info = $this->findQuoteItem($quote_item['item_id']);
     //			$supplier_required = $this->findQuoteItemDept($item_info['Item']['item_department_id']);
     //			if(!empty($supplier_required['ItemDepartment']['supplier_required'])){
     //				$supplier[$item_info['Item']['supplier_id']][] = $item_info;
     //				$po['supplier_id'] = $item_info['Item']['supplier_id'];
     //				$po['work_order_id'] = $wo->id;
     //				$po['purchase_order_num'] = $quote_info['Quote']['quote_number'];
     //				$po['quote_id'] = $quote_info['Quote']['id'];
     //				$po['shipment_date'] = date("Y-m-d");
     //				$po['expiry_date'] = date("Y-m-d");
     //				$po['cc_num'] = 'Test CC Number';
     //				$po['name_cc'] = 'Test CC Name';
     //				$po['payment_type'] = 'On Account';
     //				//$purchaseorder->save($po);
     //
     //				$index = 0;
     //				foreach($quote_info['CabinetOrderItem'] as $qitem){
     //					$purchaseorderitem = new PurchaseOrderItem();
     //					$item_info = $this->findQuoteItem($qitem['item_id']);
     //					$supplier_required = $this->findQuoteItemDept($item_info['Item']['item_department_id']);
     //					if(!empty($supplier_required['ItemDepartment']['supplier_required'])){
     //						$po_item[$index]['item_id'] = $item_info['Item']['id'];
     //						$po_item[$index]['code'] = $item_info['Item']['id']."|item";
     //						$po_item[$index]['purchase_order_id'] = $purchaseorder->id;
     //						$index++;
     //					}
     //				}
     //				//$purchaseorderitem->saveAll($po_item);
     //			}
     //		}exit;
     //exit;
     if ($QuoteStatus->save($quote_status)) {
         $this->redirect("http://{$_SERVER['SERVER_NAME']}{$this->webroot}work_order_manager/work_orders/detail/{$wo->id}");
     }
 }
コード例 #4
0
ファイル: PopulateSeedData.php プロジェクト: nvh3010/quancrm
 $po->column_fields["carrier"] = $carrier_array[$i];
 $po->column_fields["tracking_no"] = $trkno_array[$i];
 $po->column_fields["duedate"] = $duedate_array[$i];
 $po->column_fields["bill_street"] = $street_address_array[rand(0, $street_address_count - 1)];
 $po->column_fields["bill_city"] = $city_array[rand(0, $city_array_count - 1)];
 $po->column_fields["bill_state"] = "CA";
 $po->column_fields["bill_code"] = rand(10000, 99999);
 $po->column_fields["bill_country"] = 'USA';
 $po->column_fields["ship_street"] = $account->column_fields["bill_street"];
 $po->column_fields["ship_city"] = $account->column_fields["bill_city"];
 $po->column_fields["ship_state"] = $account->column_fields["bill_state"];
 $po->column_fields["ship_code"] = $account->column_fields["bill_code"];
 $po->column_fields["ship_country"] = $account->column_fields["bill_country"];
 $po->column_fields["currency_id"] = '1';
 $po->column_fields["conversion_rate"] = '1';
 $po->save("PurchaseOrder");
 $purchaseorder_ids[] = $po->id;
 $product_key = array_rand($product_ids);
 $productid = $product_ids[$product_key];
 //set the inventory product details in request then just call the saveInventoryProductDetails function
 $_REQUEST['totalProductCount'] = 1;
 $_REQUEST['hdnProductId1'] = $productid;
 $_REQUEST['qty1'] = $qty = 1;
 $_REQUEST['listPrice1'] = $listprice = 2200;
 $_REQUEST['comment1'] = "This is test comment for product of PurchaseOrder";
 $_REQUEST['deleted1'] = 0;
 $_REQUEST['discount_type1'] = 'amount';
 $_REQUEST['discount_amount1'] = $discount_amount = '200';
 $_REQUEST['taxtype'] = $taxtype = 'individual';
 $_REQUEST['subtotal'] = $subtotal = $qty * $listprice - $discount_amount;
 $_REQUEST['discount_type_final'] = 'amount';
コード例 #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new PurchaseOrder();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['PurchaseOrder'])) {
         $model->attributes = $_POST['PurchaseOrder'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->po_number));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionAutoCreate($suppliers_id)
 {
     $model = new PurchaseOrder();
     $model->suppliers_id = $suppliers_id;
     $model->order_status = '1';
     //since initailly PO is in draft stage
     //$model->save();
     if ($model->save()) {
         //echo "supplier id".$model->suppliers_id;
         /*WE are passing here the purchase order id
          * $model->id is id of purchase order table
          */
         $this->redirect(array('preview', 'id' => $model->id));
     }
 }
コード例 #7
0
 private function create_po($data, $work_id)
 {
     $quote_id = $data['WorkOrder']['quote_id'];
     App::uses('Quote', 'QuoteManager.Model');
     App::uses('PurchaseOrder', 'PurchaseOrderManager.Model');
     $quote = new Quote();
     $purchaseOrder = new PurchaseOrder();
     $quote->recursive = 0;
     $quoteInfo = $quote->find('all', array('conditions' => array('Quote.id' => $quote_id)));
     //set po id
     $po_id = $purchaseOrder->find('list', array('fields' => array('id')));
     $tmp_po_id = 0;
     if (count($po_id) > 0) {
         $tmp_po_id = array_pop($po_id) + 1;
     } else {
         $tmp_po_id = 1;
     }
     $all_items = $this->QuoteItem->ListQuoteItems($quote_id);
     //    debug($all_items);
     //    exit;
     $all_items = $this->QuoteItem->AdjustPOItem($all_items);
     $quantity_list = $all_items['quantity_list'];
     $price_list = $all_items['price_list'];
     $title_list = $all_items['title_list'];
     $name_list = $all_items['name_list'];
     $supplier_list = $this->QuoteItem->SupplierAndItemInfo();
     $total_cost = 0.0;
     $index1 = 0;
     $item_have = false;
     foreach ($supplier_list as $key => $supplier) {
         $po_data['PurchaseOrder'] = array();
         $po_data['PurchaseOrderItem'] = array();
         //debug($supplier);
         $index2 = 0;
         $item_total_cost = 0.0;
         foreach ($supplier['item'] as $item_key => $item) {
             if ($quantity_list && is_array($quantity_list)) {
                 if (array_key_exists($item, $quantity_list)) {
                     //debug($quantity_list[$item]);
                     $po_data['PurchaseOrderItem'][$index2]['quantity'] = $quantity_list[$item];
                     $po_data['PurchaseOrderItem'][$index2]['code'] = $item;
                     $item_total_cost += $price_list[$item] * $quantity_list[$item];
                     //debug($item);
                     //debug($quantity_list[$item]);
                     //debug($price_list[$item]);
                     //debug($item_total_cost);
                     $item_arr = explode('|', $item);
                     $item_id = $item_arr[1] == 'item' ? $item_arr[0] : 0;
                     $cabite_id = $item_arr[1] == 'cabinet' ? $item_arr[0] : 0;
                     $door_id = $item_arr[1] == 'door' || $item_arr[1] == 'drawer' || $item_arr[1] == 'wall_door' ? $item_arr[0] : 0;
                     $po_data['PurchaseOrderItem'][$index2]['item_id'] = $item_id;
                     $po_data['PurchaseOrderItem'][$index2]['cabinet_id'] = $cabite_id;
                     $po_data['PurchaseOrderItem'][$index2]['door_id'] = $door_id;
                     $index2++;
                     //set item in supplier
                     $item_have = true;
                 }
             }
         }
         if ($item_have) {
             $value = $this->QuoteItem->auto_generate_number('Purchase Order');
             $po_data['PurchaseOrder']['id'] = $tmp_po_id;
             $po_data['PurchaseOrder']['supplier_id'] = $key;
             $po_data['PurchaseOrder']['purchase_order_num'] = $value;
             $po_data['PurchaseOrder']['quote_id'] = $quote_id;
             $po_data['PurchaseOrder']['work_order_id'] = $work_id;
             $po_data['PurchaseOrder']['tax_gst'] = $supplier['gst'];
             $po_data['PurchaseOrder']['order_subtotal'] = $item_total_cost;
             $gst_val = $item_total_cost * $supplier['gst'] / 100;
             $pst_val = $item_total_cost * $supplier['pst'] / 100;
             $po_data['PurchaseOrder']['total_amount'] = $item_total_cost + $pst_val + $gst_val;
             $po_data['PurchaseOrder']['tax_pst'] = $supplier['pst'];
             $item_have = false;
             //debug($po_data);
             $purchaseOrder->save($po_data);
             //        $email = new CakeEmail();
             //        $email->config('gmail');
             //        $email->from(array('*****@*****.**' => 'Zenliving'));
             //        $email->to('*****@*****.**');
             //        $email->subject('Zenliving');
             //        $email->send('My message');
             $to = $supplier['email'];
             $subject = "Test mail";
             $message = "Hello! This is a test message.";
             $from = "*****@*****.**";
             $headers = "From:" . $from;
             mail($to, $subject, $message, $headers);
             //echo "Mail Sent.";
             $tmp_po_id++;
         }
     }
 }