public function addRecieveAction()
 {
     $db = new Application_Model_DbTable_DbGlobal();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $payment_purchase_order = new purchase_Model_DbTable_DbPurchaseVendor();
         $payment_purchase_order->vendorPurchaseOrderPayment($data);
         Application_Form_FrmMessage::message("Purchase has been received!");
         if ($data['payment'] == 'Save New') {
             Application_Form_FrmMessage::redirectUrl("/purchase/index/add-purchase");
             //$this->_redirect("purchase/index/add-purchase");
         } else {
             $this->_redirect("/purchase/index/index");
         }
         //not yet use in this version
         // 				elseif(@$data['Save']=='Save'){
         // 					$payment_purchase_order = new purchase_Model_DbTable_DbPurchaseVendor();
         // 					$payment_purchase_order -> VendorOrder($data);
         // 					$this->_redirect("purchase/index/index");
         // 				}
         // 				elseif(@$data['New']=='New'){
         // 					$this->_redirect("purchase/index/add-purchase");
         // 				}
     }
     $user = $this->GetuserInfoAction();
     if ($user["level"] != 1 and $user["level"] != 2) {
         $this->_redirect("purchase/index/index");
     }
     ///link left not yet get from DbpurchaseOrder
     $frm_purchase = new Application_Form_purchase(null);
     $form_add_purchase = $frm_purchase->productOrder(null);
     Application_Model_Decorator::removeAllDecorator($form_add_purchase);
     $this->view->form_purchase = $form_add_purchase;
     $formpopup = new Application_Form_FrmPopup(null);
     $formproduct = $formpopup->popuProduct(null);
     Application_Model_Decorator::removeAllDecorator($formproduct);
     $this->view->form_product = $formproduct;
     //for customer
     $formpopup = $formpopup->popupCustomer(null);
     Application_Model_Decorator::removeAllDecorator($formpopup);
     $this->view->form_customer = $formpopup;
     //for add location
     $formAdd = $formpopup->popuLocation(null);
     Application_Model_Decorator::removeAllDecorator($formAdd);
     $this->view->form_addstock = $formAdd;
     $form_agent = $formpopup->popupSaleAgent(null);
     Application_Model_Decorator::removeAllDecorator($form_agent);
     $this->view->form_agent = $form_agent;
 }
 public function advanceAction()
 {
     $db = new Application_Model_DbTable_DbGlobal();
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     // 		$r = new purchase_Model_DbTable_DbPurchaseVendor();
     // 		$r->updatePurcaheToInProgress($id);
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         //print_r($data);
         if (isset($data["payment"]) == "UPDATE") {
             $update_purchase = new purchase_Model_DbTable_DbAdvance();
             $get_result = $update_purchase->updatePurchaseOrder($data);
         } elseif (isset($data["recieve_paid"])) {
             $recieve_paid = new purchase_Model_DbTable_DbAdvance();
             $result = $recieve_paid->receivePaidOrder($data);
             Application_Form_FrmMessage::message("Product have been recieved Success!!");
             Application_Form_FrmMessage::redirectUrl("/purchase/advance/advance/id/" . $id);
         } elseif (isset($data["reorder"])) {
             $reorder = new purchase_Model_DbTable_DbAdvance();
             $update_reoder = $reorder->rePurchaseOrder($data);
             Application_Form_FrmMessage::message("Product have been reoder Success!!");
         }
     }
     ///link left not yet get from DbpurchaseOrder
     // 		$session_vendor_info = new Zend_Session_Namespace('vendor_info');
     // 		$rows= $session_vendor_info->vendorinfo;
     //		print_r($rows);exit();
     $purchase = new purchase_Model_DbTable_DbPurchaseOrder();
     $rows = $purchase->purchaseInfo($id);
     $formStock = new Application_Form_purchase();
     $formpurchase_info = $formStock->productOrder($rows);
     Application_Model_Decorator::removeAllDecorator($formpurchase_info);
     // omit default zend html tag
     $this->view->form_purchase = $formpurchase_info;
     $this->view->status = $rows["status"];
     //get item of this order
     // 		$orderModel = new purchase_Model_DbTable_DbPurchaseOrder();
     // 		$orderDetail = $orderModel->getPurchaseID($id);
     // 		$this->view->rowsOrder = $orderDetail;
     $session_record_order = new Zend_Session_Namespace('record_order');
     //create in update purchase order in page indexcontroller action update
     $orderDetail = $session_record_order->orderDetail;
     $this->view->rowsOrder = $orderDetail;
     $sql = "SELECT si.order_id,CONCAT(p.item_name,' (',p.item_code,' )') AS item_name,p.qty_perunit ,p.pro_id,si.remark as pi_remark,si.qty_order,si.price,si.total_befor,si.disc_type,\n\t\tsi.disc_value,si.is_free,si.sub_total,s.discount_value,s.`remark`,s.`discount_value`,s.`paid`,s.net_total,s.`all_total`,s.`balance`\n\t\tFROM tb_purchase_order_item AS si,tb_product AS p ,tb_purchase_order AS s\n\t\t WHERE p.pro_id = si.pro_id AND si.order_id = s.order_id AND  si.order_id={$id}";
     $result = $db->getGlobalDb($sql);
     $this->view->orderItem = $result;
     // 		 if($rows['status']==4){
     // 		 	Application_Form_FrmMessage::message("You Can't Access Advance! Order Is Payment Already");
     // 		 	//$this->_redirect("/purchase/index/detail-purchase-order/id/".$id);
     // 		 }
     //for get item receive qty order
     $qty_receive = new purchase_Model_DbTable_DbPurchaseAdvance();
     $row_receive = $qty_receive->getProductReceived($id);
     //print_r($row_receive);
     $this->view->rowsreceived = $row_receive;
     // item option in select
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->itemsOption = $itemRows;
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->items = $itemRows;
     //get control
     $formControl = new Application_Form_FrmAction(null);
     $formViewControl = $formControl->AllAction(null);
     Application_Model_Decorator::removeAllDecorator($formViewControl);
     $this->view->control = $formViewControl;
     //for add product;
     $formpopup = new Application_Form_FrmPopup(null);
     $formproduct = $formpopup->popuProduct(null);
     Application_Model_Decorator::removeAllDecorator($formproduct);
     $this->view->form = $formproduct;
     //for add vendor
     $formStockAdd = $formpopup->popupVendor(null);
     Application_Model_Decorator::removeAllDecorator($formStockAdd);
     $this->view->form_vendor = $formStockAdd;
     //for add location
     $formAdd = $formpopup->popuLocation(null);
     Application_Model_Decorator::removeAllDecorator($formAdd);
     $this->view->form_addstock = $formAdd;
     // item option in select
     // 		$items = new Application_Model_GlobalClass();
     // 		$itemRows = $items->getProductOption();
     // 		$this->view->itemsOption = $itemRows;
 }
 public function updateSalesAction()
 {
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     if ($this->getRequest()->isPost()) {
         //just block only but can use other version
         $data = $this->getRequest()->getPost();
         // 			if($data["status"]!=="Paid"){
         // 				if(@$data['payment']!==''){
         // 					$update_payment_order = new sales_Model_DbTable_DbSalesOrder();
         // 					$update_payment_order->updateCustomerOrderPayment($data);
         // 				}
         // 				elseif(@$data['Update']=='Update'){
         // 					$update_order = new sales_Model_DbTable_DbSalesOrder();
         // 					//not yet dork stock in table inventory
         // 					$update_order->updateCustomerOrder($data);
         // 				}
         // 			}
         // 			else{
         // 				Application_Form_FrmMessage::message("Cann't Edit!Sales Order Has Been Payment Already");
         // 				Application_Form_FrmMessage::redirectUrl("/sales/sales-order/index");
         // 			}
         //for new version
         $sale_order = new sales_Model_DbTable_DbCustomerOrder();
         if (isset($data["payment"])) {
             if ($data["oldStatus"] == 6) {
                 $addOrder = new sales_Model_DbTable_DbSalesOrder();
                 $addOrder->CustomerAddOrderPayment($data);
                 Application_Form_FrmMessage::message("You has been Re-Order successe!");
                 Application_Form_FrmMessage::redirectUrl("/sales/sales-order/index");
             } else {
                 $sale_order->updateCustomerOrder($data);
                 Application_Form_FrmMessage::message("You have been Update customer order success! ");
                 Application_Form_FrmMessage::redirectUrl("/sales/sales-order/index");
             }
         } elseif (isset($data["cancel_order"])) {
             //for cancel customer order
             if ($data["oldStatus"] != 6) {
                 $sale_order->cancelCustomerOrder($data);
                 Application_Form_FrmMessage::message("You have been cancel customer order success! ");
                 Application_Form_FrmMessage::redirectUrl("/sales/sales-order/index");
             } else {
                 Application_Form_FrmMessage::message("Can not cancel again!Becuase You have been cancel customer order already!");
                 Application_Form_FrmMessage::redirectUrl("/sales/sales-order/index");
             }
             // 				$sale_order->cancelCustomerOrder($data);
             // 				Application_Form_FrmMessage::message("You have been cancel customer order success! ");
             // 				Application_Form_FrmMessage::redirectUrl("/sales/sales-order/index");
         }
     }
     $user = $this->GetuserInfoAction();
     if ($user["level"] != 1 and $user["level"] != 2) {
         $gb = new Application_Model_DbTable_DbGlobal();
         $exist = $gb->userSaleOrderExist($id, $user["location_id"]);
         if ($exist == "") {
             $this->_redirect("sales/sales-order/index");
         }
     }
     $sql = "SELECT o.order_id,o.customer_id,o.LocationId,o.order,o.sales_ref,o.date_order,o.status,o.payment_method,o.currency_id,\n\t\t\to.remark,o.net_total,o.discount_type,o.discount_value,o.paid,o.all_total,o.balance,\n\t\t\tc.contact_name,c.phone,c.add_name,c.add_remark\n\t\t\tFROM tb_sales_order AS o\n\t\t\tINNER JOIN tb_customer AS c ON c.customer_id= o.customer_id\n\t\t\tINNER JOIN tb_sales_order_item AS so ON so.order_id=o.order_id\n\t\t\tWHERE o.order_id=" . $id;
     $db = new Application_Model_DbTable_DbGlobal();
     $row = $db->getGlobalDbRow($sql);
     $formStock = new Application_Form_purchase();
     $formStockEdit = $formStock->SalesOrder($row);
     Application_Model_Decorator::removeAllDecorator($formStockEdit);
     // omit default zend html tag
     $this->view->form = $formStockEdit;
     $this->view->status_so = $row['status'];
     if ($row['status'] == 1) {
         $this->_redirect("sales/sales-order/update-customer-quote/id/{$id}");
     }
     //get item of this lost
     $orderModel = new sales_Model_DbTable_DbOrder();
     $orderDetail = $orderModel->getSalesOderID($id);
     $this->view->rowsOrder = $orderDetail;
     // item option in select
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->itemsOption = $itemRows;
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->items = $itemRows;
     // 		$formControl = new Application_Form_FrmAction(null);
     // 		$formViewControl = $formControl->AllAction(null);
     // 		Application_Model_Decorator::removeAllDecorator($formViewControl);
     // 		$this->view->control = $formViewControl;
     //for add product;
     $formpopup = new Application_Form_FrmPopup(null);
     $formproduct = $formpopup->popuProduct(null);
     Application_Model_Decorator::removeAllDecorator($formproduct);
     $this->view->form_product = $formproduct;
     //for customer
     $formpopup = $formpopup->popupCustomer(null);
     Application_Model_Decorator::removeAllDecorator($formpopup);
     $this->view->form_customer = $formpopup;
     //for add location
     $formAdd = $formpopup->popuLocation(null);
     Application_Model_Decorator::removeAllDecorator($formAdd);
     $this->view->form_addstock = $formAdd;
     $form_agent = $formpopup->popupSaleAgent(null);
     Application_Model_Decorator::removeAllDecorator($form_agent);
     $this->view->form_agent = $form_agent;
 }
 public function advanceTestAction()
 {
     $db = new Application_Model_DbTable_DbGlobal();
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     $r = new purchase_Model_DbTable_DbPurchaseVendor();
     $r->updatePurcaheToInProgress($id);
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
     }
     ///link left not yet get from DbpurchaseOrder
     $session_vendor_info = new Zend_Session_Namespace('vendor_info');
     $rows = $session_vendor_info->vendorinfo;
     //		print_r($rows);exit();
     // 		$purchase = new purchase_Model_DbTable_DbPurchaseOrder();
     // 		$rows = $purchase->purchaseInfo($id);
     $formStock = new Application_Form_purchase();
     $formpurchase_info = $formStock->productOrder($rows);
     Application_Model_Decorator::removeAllDecorator($formpurchase_info);
     // omit default zend html tag
     $this->view->form_purchase = $formpurchase_info;
     //get item of this order
     // 		$orderModel = new purchase_Model_DbTable_DbPurchaseOrder();
     // 		$orderDetail = $orderModel->getPurchaseID($id);
     // 		$this->view->rowsOrder = $orderDetail;
     $session_record_order = new Zend_Session_Namespace('record_order');
     //create in update purchase order in page indexcontroller action update
     $orderDetail = $session_record_order->orderDetail;
     $this->view->rowsOrder = $orderDetail;
     if ($rows['status'] == 4) {
         Application_Form_FrmMessage::message("You Can't Access Advance! Order Is Payment Already");
         //$this->_redirect("/purchase/index/detail-purchase-order/id/".$id);
     }
     //for get item receive qty order
     $qty_receive = new purchase_Model_DbTable_DbPurchaseAdvance();
     $row_receive = $qty_receive->getProductReceived($id);
     //print_r($row_receive);
     $this->view->rowsreceived = $row_receive;
     // item option in select
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->itemsOption = $itemRows;
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->items = $itemRows;
     //get control
     $formControl = new Application_Form_FrmAction(null);
     $formViewControl = $formControl->AllAction(null);
     Application_Model_Decorator::removeAllDecorator($formViewControl);
     $this->view->control = $formViewControl;
     //for add product;
     $formpopup = new Application_Form_FrmPopup(null);
     $formproduct = $formpopup->popuProduct(null);
     Application_Model_Decorator::removeAllDecorator($formproduct);
     $this->view->form = $formproduct;
     //for add vendor
     $formStockAdd = $formpopup->popupVendor(null);
     Application_Model_Decorator::removeAllDecorator($formStockAdd);
     $this->view->form_vendor = $formStockAdd;
     //for add location
     $formAdd = $formpopup->popuLocation(null);
     Application_Model_Decorator::removeAllDecorator($formAdd);
     $this->view->form_addstock = $formAdd;
     // item option in select
     $items = new Application_Model_GlobalClass();
     $itemRows = $items->getProductOption();
     $this->view->itemsOption = $itemRows;
 }