public function updateVendorAction()
 {
     $session_stock = new Zend_Session_Namespace('stock');
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         $vendor = new purchase_Model_DbTable_DbAddVendor();
         $vendor->updateVendor($post);
         $this->_redirect("purchase/vendor/index");
     }
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     // show form with value
     $sql = "SELECT * FROM tb_vendor WHERE vendor_id=" . $id;
     $db = new Application_Model_DbTable_DbGlobal();
     $row = $db->getGlobalDbRow($sql);
     // lost item info
     $formStock = new purchase_Form_FrmVendor($row);
     $session_stock->stockID;
     $formStockEdit = $formStock->AddVendorForm($row, $session_stock->stockID);
     Application_Model_Decorator::removeAllDecorator($formStockEdit);
     // omit default zend html tag
     $this->view->orderForm = $formStockEdit;
     //control action
     $formControl = new Application_Form_FrmAction(null);
     $formViewControl = $formControl->AllAction(null);
     Application_Model_Decorator::removeAllDecorator($formViewControl);
     $this->view->control = $formViewControl;
 }
Example #2
0
 public static function getProductCode()
 {
     $db = new Application_Model_DbTable_DbGlobal();
     $sql = "SELECT  pro_id as amount FROM `tb_product` ORDER BY pro_id DESC LIMIT 1 ";
     $acc_no = $db->getGlobalDbRow($sql);
     $acc_no = $acc_no['amount'];
     $new_acc_no = (int) $acc_no + 1;
     $acc_no = strlen((int) $acc_no + 1);
     $pre = "";
     for ($i = $acc_no; $i < 3; $i++) {
         $pre .= '0';
     }
     return "KEM" . $pre . $new_acc_no;
 }
Example #3
0
 public static function getProductCode()
 {
     $db = new Application_Model_DbTable_DbGlobal();
     $sql = "SELECT COUNT(id) AS amount FROM tb_product";
     $acc_no = $db->getGlobalDbRow($sql);
     $acc_no = $acc_no['amount'];
     $new_acc_no = (int) $acc_no + 1;
     $acc_no = strlen((int) $acc_no + 1);
     $pre = "";
     for ($i = $acc_no; $i < 3; $i++) {
         $pre .= '0';
     }
     return "PC" . $pre . $new_acc_no;
 }
 public function getPurchaseidAction()
 {
     if ($this->getRequest()->isPost()) {
         $db = new Application_Model_DbTable_DbGlobal();
         $post = $this->getRequest()->getPost();
         $invoice = $post['invoice_id'];
         $sqlinfo = "SELECT * FROM `tb_purchase_order` WHERE order_id = {$invoice} LIMIT 1";
         $rowinfo = $db->getGlobalDbRow($sqlinfo);
         $sql = "SELECT pui.qty_order,pui.pro_id,pui.price,pui.sub_total\n\t\t\t\t\t,(SELECT pur.order FROM tb_purchase_order as pur WHERE pur.order_id = pui.order_id ) as order_no\n\t\t\t\t\t,(SELECT pur.all_total FROM tb_purchase_order as pur WHERE pur.order_id = pui.order_id ) as all_total\n\t\t\t\t\t,(SELECT pr.qty_perunit FROM tb_product AS pr WHERE pr.pro_id = pui.pro_id LIMIT 1) AS qty_perunit\n      \t\t\t\t,(SELECT pr.item_name FROM tb_product AS pr WHERE pr.pro_id = pui.pro_id LIMIT 1) AS item_name\n\t\t\t\t\t,(SELECT pr.pro_id FROM tb_product AS pr WHERE pr.pro_id = pui.pro_id LIMIT 1) AS pro_id\n      \t\t\t\t,(SELECT `label` FROM tb_product AS pr WHERE pr.pro_id = pui.pro_id LIMIT 1) AS label\n     \t\t\t\t,(SELECT `measure_name` FROM `tb_measure` AS ms WHERE ms.id=(SELECT measure_id FROM tb_product WHERE pro_id=pui.`pro_id`)) AS measure_name\n      \t\t\tFROM `tb_purchase_order_item` AS pui WHERE pui.order_id = " . $invoice;
         $rows = $db->getGlobalDb($sql);
         $result = array('poinfo' => $rowinfo, 'item' => $rows);
         echo Zend_Json::encode($result);
         exit;
     }
 }
 public function updateVendorCancellOrder($data)
 {
     try {
         $db = $this->getAdapter();
         $db->beginTransaction();
         $db_global = new Application_Model_DbTable_DbGlobal();
         $session_user = new Zend_Session_Namespace('auth');
         $userName = $session_user->user_name;
         $GetUserId = $session_user->user_id;
         //for update order by id\
         $id_order_update = $data['id'];
         //update info of order in tb_purchase order
         // 			if($data["status"]==6){
         // 			}
         $info_purchase_order = array("vendor_id" => $data['v_name'], "LocationId" => $data["LocationId"], "order" => $data['txt_order'], "date_order" => $data['order_date'], "status" => $data["status"], "remark" => $data['remark'], "user_mod" => $GetUserId, "timestamp" => new Zend_Date(), "paid" => $data['paid'], "all_total" => $data['totalAmoun'], "balance" => $data['remain']);
         $db_global->updateRecord($info_purchase_order, $id_order_update, "order_id", "tb_purchase_order");
         unset($info_purchase_order);
         // Insert recieved order
         $recieved_id = $data["recieve_id"];
         $ids = explode(',', $data['identity']);
         $sql_recieve = new purchase_Model_DbTable_DbPurchaseOrder();
         $result = $sql_recieve->recieved_info($id_order_update);
         $prifix = "SELECT * FROM tb_setting WHERE `code` =16";
         $ro = $db_global->getGlobalDbRow($prifix);
         $RO = $ro["key_value"];
         $date = new Zend_Date();
         $recieve_no = $RO . $date->get('hh-mm-ss');
         if ($result) {
             //if($data["oldStatus"]==5 or $data["oldStatus"]==4){
             if ($data["status"] == 5 or $data["status"] == 4) {
                 $data_recieved_order = array("recieve_type" => 1, "order_id" => $id_order_update, "order_no" => $data["txt_order"], "vendor_id" => $data['v_name'], "location_id" => $data["LocationId"], "date_recieve" => new Zend_Date(), "status" => $data['status'], "is_active" => 1, "paid" => $data['paid'], "all_total" => $data['totalAmoun'], "balance" => $data['remain'], "user_recieve" => $GetUserId);
                 $recieved_order = $db_global->updateRecord($data_recieved_order, $recieved_id, "recieve_id", "tb_recieve_order");
                 unset($data_recieved_order);
             } else {
                 $data_recieved_order = array("recieve_type" => 1, "order_id" => $id_order_update, "order_no" => $data["txt_order"], "vendor_id" => $data['v_name'], "location_id" => $data["LocationId"], "date_recieve" => new Zend_Date(), "status" => $data['status'], "is_active" => 0, "paid" => $data['paid'], "all_total" => $data['totalAmoun'], "balance" => $data['remain'], "user_recieve" => $GetUserId);
                 $recieved_order = $db_global->updateRecord($data_recieved_order, $recieved_id, "recieve_id", "tb_recieve_order");
                 unset($data_recieved_order);
             }
             //}
             $sqls = "DELETE FROM tb_recieve_order_item WHERE recieve_id IN ({$recieved_id})";
             $db_global->deleteRecords($sqls);
             unset($sqls);
             foreach ($ids as $i) {
                 $recieved_item[$i] = array("recieve_id" => $recieved_id, "pro_id" => $data['item_id_' . $i], "order_id" => $id_order_update, "qty_order" => $data['qty' . $i], "qty_recieve" => $data['qty' . $i], "price" => $data['price' . $i], "total_before" => $data['total' . $i], "sub_total" => $data['total' . $i]);
                 $db->insert("tb_recieve_order_item", $recieved_item[$i]);
                 unset($recieved_item[$i]);
             }
         } else {
             $sql = "SELECT * FROM tb_setting WHERE `code`=16";
             $ro = $db_global->getGlobalDbRow($sql);
             $RO = $ro["key_value"];
             $date = new Zend_Date();
             $recieve_no = $RO . $date->get('hh-mm-ss');
             if ($data["status"] == 5 or $data["status"] == 4) {
                 $data_recieved_order = array("recieve_type" => 1, "order_id" => $id_order_update, "recieve_no" => $recieve_no, "order_no" => $data["txt_order"], "vendor_id" => $data['v_name'], "location_id" => $data["LocationId"], "order_date" => new Zend_Date(), "date_recieve" => new Zend_Date(), "status" => $data['status'], "is_active" => 1, "paid" => $data['paid'], "all_total" => $data['totalAmoun'], "balance" => $data['remain'], "user_recieve" => $GetUserId);
                 $recieved_order = $db_global->addRecord($data_recieved_order, "tb_recieve_order");
                 unset($data_recieved_order);
                 foreach ($ids as $i) {
                     $recieved_item[$i] = array("recieve_id" => $recieved_order, "pro_id" => $data['item_id_' . $i], "order_id" => $id_order_update, "qty_order" => $data['qty' . $i], "qty_recieve" => $data['qty' . $i], "price" => $data['price' . $i], "total_before" => $data['total' . $i], "sub_total" => $data['total' . $i]);
                     $db->insert("tb_recieve_order_item", $recieved_item[$i]);
                     unset($recieved_item[$i]);
                 }
             }
         }
         // end update info of order in tb_purchase order
         // Delete old purchase order item before insert new purchase order item in old order_id
         $sql = "DELETE FROM tb_purchase_order_item WHERE order_id IN ({$id_order_update})";
         $db_global->deleteRecords($sql);
         unset($sql);
         $sql_history = "DELETE FROM tb_purchase_order_history WHERE `order` IN ({$id_order_update})";
         $db_global->deleteRecords($sql_history);
         unset($sql_history);
         /// update
         $ids = explode(',', $data['identity']);
         //add order in tb_inventory must update code again 9/8/13
         //print_r($ids);exit();
         foreach ($ids as $i) {
             // Insert recieved order item
             $data_item[$i] = array('order_id' => $id_order_update, 'pro_id' => $data['item_id_' . $i], 'qty_order' => $data['qty' . $i], 'price' => $data['price' . $i], 'sub_total' => $data['total' . $i], 'total_befor' => $data['total' . $i], 'remark' => $data['remark_' . $i]);
             //print_r($data_item); echo "<br />";echo "<br />";
             $db->insert("tb_purchase_order_item", $data_item[$i]);
             unset($data_item[$i]);
             $data_history[$i] = array('order' => $id_order_update, 'pro_id' => $data['item_id_' . $i], 'type' => 1, 'customer_id' => $data['v_name'], 'status' => $data["status"], 'order_total' => $data['total' . $i], 'qty' => $data['qty' . $i], 'unit_price' => $data['price' . $i], 'sub_total' => $data['total' . $i], 'date' => $data["old_history_date"], 'last_update_date' => new Zend_Date());
             //print_r($data_history);exit();
             $db->insert("tb_purchase_order_history", $data_history[$i]);
             unset($data_history[$i]);
             $locationid = $data['LocationId'];
             $itemId = $data['item_id_' . $i];
             $qtyrecord = $data['qty' . $i];
             //qty on 1 record
             // Update stock in tb_product
             $rows = $db_global->productLocationInventory($itemId, $locationid);
             //to check product location
             //print_r($rows); exit();
             if ($rows) {
                 $getrecord_id = $rows["ProLocationID"];
                 if ($data["status"] == 5 or $data["status"] == 4) {
                     $itemOnHand = array('qty_onhand' => $rows["qty_onhand"] + $qtyrecord, 'qty_available' => $rows["qty_available"] + $qtyrecord, 'last_mod_date' => new Zend_date());
                     $db_global->updateRecord($itemOnHand, $itemId, "pro_id", "tb_product");
                     unset($itemOnHand);
                 } else {
                     $itemOnHand = array('qty_onorder' => $rows["pqty_onorder"] + $qtyrecord, 'last_mod_date' => new Zend_date());
                     $db_global->updateRecord($itemOnHand, $itemId, "pro_id", "tb_product");
                     unset($itemOnHand);
                 }
                 //End update total stock
                 // Update product Location
                 if ($data["status"] == 5 or $data["status"] == 4) {
                     $updatedata = array('qty' => $rows['qty'] + $qtyrecord, 'last_mod_date' => new Zend_date());
                     $db_global->updateRecord($updatedata, $getrecord_id, "ProLocationID", "tb_prolocation");
                     unset($updatedata);
                 } else {
                     $updatedata = array('qty_onorder' => $rows['qty_onorder'] + $qtyrecord, 'last_mod_date' => new Zend_date());
                     $db_global->updateRecord($updatedata, $getrecord_id, "ProLocationID", "tb_prolocation");
                     unset($updatedata);
                 }
                 //End update stock product location						//update stock record
             } else {
                 //insert stock ;
                 $rows_pro_exit = $db_global->productLocation($itemId, $locationid);
                 // check product location exist
                 // if product exist Update qty in tb_prolocation
                 if ($rows_pro_exit) {
                     if ($data["status"] == 5 or $data["status"] == 4) {
                         $updatedata = array('qty' => $rows['qty'] + $qtyrecord, 'last_mod_date' => new Zend_date());
                         $itemid = $db_global->updateRecord($updatedata, $rows_pro_exit['ProLocationID'], "ProLocationID", "tb_prolocation");
                         unset($updatedata);
                     } else {
                         $updatedata = array('qty_onorder' => $rows['qty_onorder'] + $qtyrecord, 'last_mod_date' => new Zend_date());
                         $itemid = $db_global->updateRecord($updatedata, $rows_pro_exit['ProLocationID'], "ProLocationID", "tb_prolocation");
                         unset($updatedata);
                     }
                     // End if product exist Update qty in tb_prolocation
                 } else {
                     // If product not exist insert New product in tb_prolocation
                     $insertdata = array('pro_id' => $itemId, 'LocationId' => $locationid, 'last_usermod' => $GetUserId, 'qty' => $qtyrecord, 'last_mod_date' => new Zend_Date());
                     //update stock product location
                     $db->insert("tb_prolocation", $insertdata);
                     unset($insertdata);
                 }
                 // End If product not exist insert New product in tb_prolocation
                 $rowitem = $db_global->InventoryExist($itemId);
                 //to check product exist
                 // If productt exist update product in tb_product
                 if ($rowitem) {
                     if ($data["status"] == 5 or $data["status"] == 4) {
                         $itemOnHand = array('qty_onhand' => $rows["qty_onhand"] + $qtyrecord, 'qty_available' => $rows["qty_available"] + $qtyrecord, 'last_mod_date' => new Zend_date());
                         $itemid = $db_global->updateRecord($itemOnHand, $itemId, "pro_id", "tb_product");
                         unset($itemOnHand);
                     } else {
                         $itemOnHand = array('qty_onorder' => $rows["qty_onrder"] + $qtyrecord, 'last_mod_date' => new Zend_date());
                         $itemid = $db_global->updateRecord($itemOnHand, $itemId, "pro_id", "tb_product");
                         unset($itemOnHand);
                     }
                     //update total stock
                     // 						$itemid=$db_global->updateRecord($itemOnHand,$itemId,"pro_id","tb_product");
                     // 						unset($itemOnHand);
                     // If productt exist update product in tb_product
                 } else {
                     // If product not exist insert new product in tb_product
                     $dataInventory = array('pro_id' => $itemId, 'qty_onhand' => $qtyrecord, 'qty_available' => $qtyrecord, 'last_mod_date' => new Zend_date());
                     $db->insert("tb_product", $dataInventory);
                     unset($dataInventory);
                     //update stock product location
                 }
             }
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         $e->getMessage();
         //echo $theCauseOfErrorOnlyDoNotRedirectToError;
         //exit();
     }
 }
 public function getfillterAction()
 {
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         $ids = $post["customer_name"];
         $sql = "SELECT id,branch,receipt,code_call,customer_id,type_call,owner_call,\r\n\t\t\t\tcallnumber,create_date,date_debt,term,amount_term,date_line,curr_type,\r\n\t\t\t\tamount_debt,note,term_fun,charge_term,amount_money FROM `ln_callecteralllist` WHERE `customer_id`=" . $ids;
         $db = new Application_Model_DbTable_DbGlobal();
         $row = $db->getGlobalDbRow($sql);
         print_r(Zend_Json::encode($row));
         exit;
     }
 }
Example #7
0
 public function getfillteraddAction()
 {
     if ($this->getRequest()->IsPost()) {
         $data = $this->getRequest()->getPost();
         $username = $data['username'];
         $sql = "SELECT username FROM tbwu_acl_user WHERE username = '******'";
         $db = new Application_Model_DbTable_DbGlobal();
         $row = $db->getGlobalDbRow($sql);
         echo Zend_Json::encode($row);
         exit;
     }
 }
 public function VendorOrder($data)
 {
     $db_global = new Application_Model_DbTable_DbGlobal();
     $db = $this->getAdapter();
     $session_user = new Zend_Session_Namespace('auth');
     $userName = $session_user->user_name;
     $GetUserId = $session_user->user_id;
     $idrecord = $data['v_name'];
     $datainfo = array("contact_name" => $data['contact'], "phone" => $data['txt_phone']);
     //updage vendor info
     $itemid = $db_global->updateRecord($datainfo, $idrecord, "vendor_id", "tb_vendor");
     if ($data['txt_order'] == "") {
         $date = new Zend_Date();
         $order_add = "PO" . $date->get('hh-mm-ss');
     } else {
         $order_add = $data['txt_order'];
     }
     $info_purchase_order = array("vendor_id" => $data['v_name'], "LocationId" => $data["LocationId"], "order" => $order_add, "date_order" => $data['order_date'], "status" => 2, "payment_method" => $data['payment_name'], "currency_id" => $data['currency'], "remark" => $data['remark'], "user_mod" => $GetUserId, "timestamp" => new Zend_Date(), "version" => 1, "net_total" => $data['net_total'], "discount_type" => $data['discount_type'], "discount_value" => $data['discount_value'], "discount_real" => $data['discount_real'], "paid" => $data['paid'], "all_total" => $data['all_total'], "balance" => $data['all_total'] - $data['paid']);
     //and info of purchase order
     $purchase_id = $db_global->addRecord($info_purchase_order, "tb_purchase_order");
     unset($info_purchase_order);
     $ids = explode(',', $data['identity']);
     //   $qtyonhand=0;
     foreach ($ids as $i) {
         //add history purchase order
         $data_history = array('pro_id' => $data['item_id_' . $i], 'type' => 1, 'order' => $purchase_id, 'customer_id' => $data['v_name'], 'date' => new Zend_Date(), 'status' => 2, 'order_total' => $data['all_total'], 'qty' => $data['qty' . $i], 'unit_price' => $data['price' . $i], 'sub_total' => $data['after_discount' . $i]);
         $db_global->addRecord($data_history, "tb_purchase_order_history");
         unset($data_history);
         //add purchase order item
         $data_item[$i] = array('order_id' => $purchase_id, 'pro_id' => $data['item_id_' . $i], 'qty_order' => $data['qty' . $i], 'price' => $data['price' . $i], 'total_befor' => $data['total' . $i], 'disc_type' => $data['dis-type-' . $i], 'disc_value' => $data['dis-value' . $i], 'sub_total' => $data['after_discount' . $i]);
         $id_order_item = $db_global->addRecord($data_item[$i], "tb_purchase_order_item");
         unset($data_item[$i]);
         //update stock total inventory
         $locationid = $data['LocationId'];
         $itemId = $data['item_id_' . $i];
         $qtyrecord = $data['qty' . $i];
         //qty on 1 record
         $sql = "SELECT tv.ProdId, tv.QuantityOnOrder,tv.QuantityAvailable\n\t\t\tFROM tb_inventorytotal AS tv\n\t\t\tINNER JOIN tb_product AS p ON tv.ProdId = p.pro_id\n\t\t\tWHERE p.pro_id = " . $data['item_id_' . $i];
         $rows = $db_global->getGlobalDbRow($sql);
         if ($rows) {
             $qty_onhand = $rows["QuantityOnOrder"] + $qtyrecord;
             $qty_on_order = array("QuantityOnOrder" => $rows["QuantityOnOrder"] + $qtyrecord);
             //update total stock
             $db_global->updateRecord($qty_on_order, $itemId, "ProdId", "tb_inventorytotal");
             unset($qty_on_order);
         } else {
             $row = $db_global->InventoryExist($itemId);
             if ($row) {
                 $qty_onhand = $rows["QuantityOnOrder"] + $qtyrecord;
                 $qty_on_order = array("QuantityOnOrder" => $rows["QuantityOnOrder"] + $qtyrecord);
                 //update total stock
                 $db_global->updateRecord($qty_on_order, $itemId, "ProdId", "tb_inventorytotal");
                 unset($qty_on_order);
             } else {
                 $addInventory = array('ProdId' => $itemId, 'QuantityOnOrder' => $data['qty' . $i], 'Timestamp' => new Zend_date());
                 $db_global->addRecord($addInventory, "tb_inventorytotal");
                 unset($addInventory);
             }
         }
     }
 }
 public function getfillterdepositeAction()
 {
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         $ids = $post["partner"];
         $sql = "SELECT account_no,`cash_dollar`,`cash_bath`,cash_riel FROM cms_partner WHERE id=" . $ids;
         $db = new Application_Model_DbTable_DbGlobal();
         $row = $db->getGlobalDbRow($sql);
         print_r(Zend_Json::encode($row));
         exit;
     }
 }
 public function updateCustomerAction()
 {
     if ($this->getRequest()->isPost()) {
         try {
             $post = $this->getRequest()->getPost();
             $customer = new sales_Model_DbTable_DbCustomer();
             $customer->updateCustomer($post);
             $this->_redirect('/sales/customer/index');
         } catch (Exception $e) {
             Application_Form_FrmMessage::message("Update customer failed !");
         }
     }
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     $sql = "SELECT c.customer_id,c.type_price,c.cust_name, c.add_remark, c.contact_name,c.add_name, c.phone, \n\t\t\t\t\tc.fax,c.email, c.website,c.customer_remark,c.is_active\n\t\t\t\t\tFROM tb_customer AS c,tb_price_type as tp\n\t\t\t\t\tWHERE tp.type_id=c.type_price\n\t\t\t\t\tAND c.customer_id = " . $id . " LIMIT 1";
     $db = new Application_Model_DbTable_DbGlobal();
     $row = $db->getGlobalDbRow($sql);
     // lost item info
     $formStock = new sales_Form_FrmVendor($row);
     $formStockEdit = $formStock->AddCustomerForm($row);
     Application_Model_Decorator::removeAllDecorator($formStockEdit);
     // omit default zend html tag
     $this->view->customer_frm = $formStockEdit;
     //control action
     $formControl = new Application_Form_FrmAction(null);
     $formViewControl = $formControl->AllAction(null);
     Application_Model_Decorator::removeAllDecorator($formViewControl);
     $this->view->control = $formViewControl;
 }
 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 updateReturnItemAction()
 {
     try {
         $session_stock = new Zend_Session_Namespace('stock');
         $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
         $db_global = new Application_Model_DbTable_DbGlobal();
         $sql = "SELECT * FROM tb_return WHERE return_id =" . $id;
         $rs = $db_global->getGlobalDbRow($sql);
         if ($rs["is_active"] == 0) {
             Application_Form_FrmMessage::message("Can not update return becuase recieved already");
             Application_Form_FrmMessage::redirectUrl("/purchase/return");
         } else {
             if ($this->getRequest()->isPost()) {
                 $data = $this->getRequest()->getPost();
                 if ($data['Save']) {
                     $update_return = new purchase_Model_DbTable_DbReturnItem();
                     $rs = $update_return->updateReturnItem($data);
                     if ($rs == -1) {
                         Application_Form_FrmMessage::Sucessfull("Your product location is not exist", "/purchase/return");
                     }
                     //  					else
                     //  						Application_Form_FrmMessage::Sucessfull("Update Sucessfull", "/purchase/return");
                 }
             }
             // 		$purchase = new purchase_Model_DbTable_DbPurchaseOrder();
             // 		$rows = $purchase->purchaseInfo($id);
             // 		$db = new Application_Model_DbTable_DbGlobal();
             $returnModel = new purchase_Model_DbTable_DbSQLReturnItem();
             $row_info = $returnModel->returnInfo($id);
             $get_form = new Application_Form_FrmReturnItem();
             $session_stock = new Zend_Session_Namespace('stock');
             $frm_return = $get_form->returnItemForm($row_info);
             Application_Model_Decorator::removeAllDecorator($frm_return);
             $this->view->form_return = $frm_return;
             //get qty of return item
             $getReturnItem = $returnModel->getReturnItem($id);
             $this->view->returnItemDetail = $getReturnItem;
             //print_r($getReturnItem);exit();
             //get return item
             $getOption = new Application_Model_GlobalClass();
             $locationRows = $getOption->getLocationOption();
             $this->view->locationOption = $locationRows;
             //print_r($locationRows);exit();
             $itemRows = $getOption->getProductOption();
             $this->view->productOption = $itemRows;
             //print_r($itemRows);exit();
             $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_add_product = $formproduct;
             //for add vendor
             $formvendor = $formpopup->popupVendor(null);
             Application_Model_Decorator::removeAllDecorator($formvendor);
             $this->view->form_vendor = $formvendor;
             //for add location
             $formAdd = $formpopup->popuLocation(null);
             Application_Model_Decorator::removeAllDecorator($formAdd);
             $this->view->form_addstock = $formAdd;
             //for link advane
             $this->view->getorder_id = $id;
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
 public function updateStockAction()
 {
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     $db = new Application_Model_DbTable_DbGlobal();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($data['submit_add_close']) {
             $Model = new Product_Model_DbTable_DbAddLocation();
             $Model->updateSubStock($data);
             $this->_redirect('/product/index/index-location');
         } else {
             $this->_redirect('/product/index/index-location');
         }
     }
     // show form with value
     $stockSql = "SELECT * FROM tb_sublocation WHERE LocationId=" . $id;
     $row = $db->getGlobalDbRow($stockSql);
     $form = new Product_Form_FrmSubStock(null);
     $formlocation = $form->orderSubstockForm($row);
     Application_Model_Decorator::removeAllDecorator($formlocation);
     // omit default zend html tag
     $this->view->formstock = $formlocation;
 }
Example #14
0
 public static function getCallteralCode()
 {
     $db = new Application_Model_DbTable_DbGlobal();
     $sql = "SELECT COUNT(order_id) AS amount FROM tb_purchase_order";
     $acc_no = $db->getGlobalDbRow($sql);
     $acc_no = $acc_no['amount'];
     $new_acc_no = (int) $acc_no + 1;
     $acc_no = strlen((int) $acc_no + 1);
     $pre = "";
     for ($i = $acc_no; $i < 5; $i++) {
         $pre .= '0';
     }
     return "KEM-" . $pre . $new_acc_no;
 }
 public function getqtybyidAction()
 {
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         $item_id = $post['item_id'];
         $sql = "SELECT `qty_perunit` FROM tb_product WHERE pro_id= '{$item_id}' LIMIT 1 ";
         $db = new Application_Model_DbTable_DbGlobal();
         $row = $db->getGlobalDbRow($sql);
         /*if(!$result){
         		 $result = array('contact'=>'','phone'=>'');
         		}*/
         echo Zend_Json::encode($row);
         exit;
     }
 }
 public function cancelPurchaseOrder($data)
 {
     try {
         $db = $this->getAdapter();
         $db->beginTransaction();
         $db_global = new Application_Model_DbTable_DbGlobal();
         $session_user = new Zend_Session_Namespace('auth');
         $userName = $session_user->user_name;
         $GetUserId = $session_user->user_id;
         $id_order_update = $data['id'];
         if ($data["status"] == 4) {
             $sql_recieve_order = "SELECT `recieve_id`,`recieve_type`,order_id,`vendor_id`,`location_id`,`disc_value`,paid,`all_total`,`balance`\n\t\t\t\tFROM tb_recieve_order WHERE order_id = {$id_order_update}";
             $result_recieve = $db_global->getGlobalDbRow($sql_recieve_order);
             //print_r($result_recieve);exit();
             if ($result_recieve) {
                 $db->getProfiler()->setEnabled(true);
                 $receive = array("is_active" => 0, "user_recieve" => $GetUserId);
                 $this->_name = "tb_recieve_order";
                 $where = $this->getAdapter()->quoteInto("recieve_id=?", $result_recieve["recieve_id"]);
                 $recieve_id = $this->update($receive, $where);
                 Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
                 Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
                 $db->getProfiler()->setEnabled(false);
                 $sql_itm = "SELECT\n\t\t\t\t\t(SELECT p.pro_id FROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS pro_id\n\t\t\t\t\t\n\t\t\t\t\t,(SELECT p.qty_onorder FROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS qty_onorder\n\t\t\t\t\t\n\t\t\t\t\t,(SELECT p.qty_onhand \tFROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS qty_onhand\n\t\t\t\t\t\n\t\t\t\t\t,(SELECT p.qty_available \tFROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS qty_available\n\t\t\t\t\t\n\t\t\t\t\t, SUM(po.`qty_order`) AS qty_order FROM\n\t\t\t\t\t\n\t\t\t\t\ttb_purchase_order_item AS po WHERE po.order_id = {$id_order_update} GROUP BY po.pro_id";
                 $rows_order = $db_global->getGlobalDb($sql_itm);
                 if ($rows_order) {
                     foreach ($rows_order as $row) {
                         $row_get = $db_global->porductLocationExist($row["pro_id"], $data["old_location"]);
                         $qty_onhand = $row["qty_onhand"] - $row["qty_order"];
                         $qty_available = $row["qty_available"] - $row["qty_order"];
                         $qty = $row_get["qty"] - $row["qty_order"];
                         $qty_available_prolo = $row_get["qty_avaliable"] - $row["qty_order"];
                         if ($qty_onhand <= 0 or $qty <= 0) {
                             Application_Form_FrmMessage::message(" Can't cancel!!! The Main Stock or Location Stock is Not enough ");
                             exit;
                         } else {
                             $db->getProfiler()->setEnabled(true);
                             $update_product = array("qty_onhand" => $qty_onhand, "qty_available" => $qty_available);
                             $this->_name = "tb_product";
                             $where = $this->getAdapter()->quoteInto("pro_id=?", $row["pro_id"]);
                             $this->update($update_product, $where);
                             unset($update_product);
                             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
                             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
                             $db->getProfiler()->setEnabled(false);
                             $db->getProfiler()->setEnabled(true);
                             $update_prolocation = array("qty" => $qty, "qty_avaliable" => $qty_available_prolo);
                             $this->_name = "tb_prolocation";
                             $where = $this->getAdapter()->quoteInto("ProLocationID=?", $row_get["ProLocationID"]);
                             $this->update($update_prolocation, $where);
                             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
                             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
                             $db->getProfiler()->setEnabled(false);
                         }
                     }
                 }
             }
             $db->getProfiler()->setEnabled(true);
             $info_purchase_order = array("status" => 6);
             $this->_name = "tb_purchase_order";
             $where = $this->getAdapter()->quoteInto("order_id=?", $id_order_update);
             $this->update($info_purchase_order, $where);
             //$db_global->updateRecord($info_purchase_order,$id_order_update,"order_id","tb_purchase_order");
             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
             $db->getProfiler()->setEnabled(false);
         } elseif ($data["status"] == 3) {
         }
         $db->getProfiler()->setEnabled(true);
         $info_purchase_order = array("status" => 6);
         $this->_name = "tb_purchase_order";
         $where = $this->getAdapter()->quoteInto("order_id=?", $id_order_update);
         $this->update($info_purchase_order, $where);
         //$db_global->updateRecord($info_purchase_order,$id_order_update,"order_id","tb_purchase_order");
         Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
         Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
         $db->getProfiler()->setEnabled(false);
         $ids = explode(',', $data['identities']);
         foreach ($ids as $i) {
             if (@$data["pricefree_" . $i]) {
                 $is_free = 1;
             } else {
                 $is_free = 0;
             }
             // Insert New purchase order item in old order_id
             $db->getProfiler()->setEnabled(true);
             $data_history[$i] = array('order' => $id_order_update, 'pro_id' => $data['item_id_' . $i], 'type' => 1, 'customer_id' => $data['v_name'], 'status' => $data["status"], 'order_total' => $data['total' . $i], 'qty' => $data['qty' . $i], 'status' => 6, 'unit_price' => $data['price' . $i], 'sub_total' => $data['total' . $i], 'last_update_date' => new Zend_Date());
             $db->insert("tb_purchase_order_history", $data_history[$i]);
             unset($data_history[$i]);
             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
             $db->getProfiler()->setEnabled(false);
         }
         $sql_itm = "SELECT\n\t\t\t(SELECT p.pro_id FROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS pro_id\n\t\t\t\t\n\t\t\t,(SELECT p.qty_onorder FROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS qty_onorder\n\t\n\t\t\t,(SELECT p.qty_onhand \tFROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS qty_onhand\n\t\n\t\t\t,(SELECT p.qty_available \tFROM tb_product AS p WHERE p.pro_id = po.`pro_id`) AS qty_available\n\t\t\t\t\n\t\t\t, SUM(po.`qty_order`) AS qty_order FROM\n\t\n\t\t\ttb_purchase_order_item AS po WHERE po.order_id = {$id_order_update} GROUP BY po.pro_id";
         $rows_order = $db_global->getGlobalDb($sql_itm);
         if ($rows_order) {
             foreach ($rows_order as $row) {
                 $row_get = $db_global->porductLocationExist($row["pro_id"], $data["old_location"]);
                 $qty_onhand = $row["qty_onhand"] - $row["qty_order"];
                 $qty_available = $row["qty_available"] - $row["qty_order"];
                 $qty = $row_get["qty"] - $row["qty_order"];
                 $qty_available_prolo = $row_get["qty_avaliable"] - $row["qty_order"];
                 if ($qty_onhand <= 0 or $qty <= 0) {
                     Application_Form_FrmMessage::message("The Main Stock or Location Stock is Not enough ");
                     exit;
                 } else {
                     $db->getProfiler()->setEnabled(true);
                     $update_product = array("qty_onhand" => $qty_onhand, "qty_available" => $qty_available, "qty_onorder" => $row["qty_onorder"] + $row["qty_order"]);
                     $this->_name = "tb_product";
                     $where = $this->getAdapter()->quoteInto("pro_id=?", $row["pro_id"]);
                     $this->update($update_product, $where);
                     unset($update_product);
                     Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
                     Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
                     $db->getProfiler()->setEnabled(false);
                     $db->getProfiler()->setEnabled(true);
                     $update_prolocation = array("qty" => $qty, "qty_avaliable" => $qty_available_prolo, "qty_onorder" => $row_get["qty_onorder"] + $row["qty_order"]);
                     $this->_name = "tb_prolocation";
                     $where = $this->getAdapter()->quoteInto("ProLocationID=?", $row_get["ProLocationID"]);
                     $this->update($update_prolocation, $where);
                     Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
                     Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
                     $db->getProfiler()->setEnabled(false);
                 }
             }
         }
         /// update
         $ids = explode(',', $data['identities']);
         foreach ($ids as $i) {
             if (@$data["pricefree_" . $i]) {
                 $is_free = 1;
             } else {
                 $is_free = 0;
             }
             // Insert New purchase order item in old order_id
             $db->getProfiler()->setEnabled(true);
             $data_history[$i] = array('order' => $id_order_update, 'pro_id' => $data['item_id_' . $i], 'type' => 1, 'customer_id' => $data['v_name'], 'status' => $data["status"], 'order_total' => $data['total' . $i], 'qty' => $data['qty' . $i], 'status' => 4, 'unit_price' => $data['price' . $i], 'sub_total' => $data['total' . $i], 'last_update_date' => new Zend_Date());
             $db->insert("tb_purchase_order_history", $data_history[$i]);
             unset($data_history[$i]);
             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
             Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
             $db->getProfiler()->setEnabled(false);
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         $e->getMessage();
     }
 }
Example #17
0
	public static function getCallteralCode(){
		$db = new Application_Model_DbTable_DbGlobal();
		$sql = "SELECT COUNT(id) AS amount FROM `ln_client_callecteral`";
		$acc_no= $db->getGlobalDbRow($sql);
		$acc_no=$acc_no['amount'];
		$new_acc_no= (int)$acc_no+1;
		$acc_no= strlen((int)$acc_no+1);
		$pre = "";
		for($i = $acc_no;$i<6;$i++){
			$pre.='0';
		}
		return "CL".$pre.$new_acc_no;
	}
 public function updateSaleAgentAction()
 {
     $session_stock = new Zend_Session_Namespace('stock');
     $id = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '0';
     $db = new Application_Model_DbTable_DbGlobal();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($data["submit_update"]) {
             $update_agent = new sales_Model_DbTable_DbSalesAgent();
             $update_agent->updateSalesAgent($data);
             $this->_redirect("sales/sale-agent/index");
         } else {
             $this->_redirect("sales/sale-agent/index");
         }
     }
     // show form with value
     $sql = "SELECT * FROM tb_sale_agent where agent_id=" . $id;
     $rows = $db->getGlobalDbRow($sql);
     $formAgent = new sales_Form_FrmStock(null);
     $formShowAgent = $formAgent->showSaleAgentForm($rows, $session_stock->stockID);
     Application_Model_Decorator::removeAllDecorator($formShowAgent);
     $this->view->form_agent = $formShowAgent;
     $formpopup = new Application_Form_FrmPopup(null);
     //for add location
     $formAdd = $formpopup->popuLocation(null);
     Application_Model_Decorator::removeAllDecorator($formAdd);
     $this->view->form_addstock = $formAdd;
 }