コード例 #1
0
 public function receivedCompleted($data)
 {
     $db_global = new Application_Model_DbTable_DbGlobal();
     $advance = new purchase_Model_DbTable_DbPurchaseAdvance();
     $session_user = new Zend_Session_Namespace('auth');
     $userName = $session_user->user_name;
     $GetUserId = $session_user->user_id;
     $db = $this->getAdapter();
     $rows_tmp = $advance->purchaseOrderTMPExist($data['purchase_order']);
     if ($rows_tmp) {
         foreach ($rows_tmp as $post) {
             //add info received item
             $data_receive = array("purchase_order_id" => $data['purchase_order'], "location_id" => $post["qty_order"], "pro_id" => $post["pro_id"], "qty_order" => $post["qty_order"], "qty_receive" => $post["qty_order"], "qty_remain" => 0, "receive_date" => new Zend_Date(), "user_id" => $GetUserId, "mod_date" => new Zend_Date());
             $db->insert("tb_purchase_order_receive", $data_receive);
             $rows = $db_global->inventoryLocation($data["location_id"], $post["pro_id"]);
             if ($rows) {
                 $qty_on_order = array('QuantityOnHand' => $rows["QuantityOnHand"] + $post["qty_order"], 'QuantityOnOrder' => $rows["QuantityOnOrder"] - $post["qty_order"], 'QuantityAvailable' => $rows["QuantityAvailable"] + $post["qty_order"], 'Timestamp' => new Zend_date());
                 // 						//update total stock
                 $db_global->updateRecord($qty_on_order, $post["pro_id"], "ProdId", "tb_inventorytotal");
                 // 						unset($qty_on_order);
                 $updatedata = array('qty' => $rows["qty"] + $post["qty_order"], "last_usermod" => $GetUserId, "last_mod_date" => new Zend_Date());
                 //update stock product location
                 $db_global->updateRecord($updatedata, $rows["ProLocationID"], "ProLocationID", "tb_prolocation");
                 unset($updatedata);
                 $row_get = $advance->getItemPurchaseExist($data['purchase_order'], $post["pro_id"]);
                 if ($row_get) {
                     $data_update = array("qty_order" => $row_get["qty_order"] - $post["qty_order"]);
                     $db_global->updateRecord($data_update, $row_get["id"], "id", "tb_purchase_order_item_tmp");
                     unset($data_update);
                 }
             } else {
                 // 						$insertdata=array(
                 // 								'pro_id'     => $post["pro_id"],
                 // 								'LocationId' => $data["location_id"],
                 // 								'qty'        => $post["qty_order"]
                 // 						);
                 // 						//update stock product location
                 // 						$db->insert("tb_prolocation", $insertdata);
                 // // 						unset($insertdata);
                 // // 						//update tmp purchase order
                 // 						$row_get = $advance-> getItemPurchaseExist($data["purchase_id"], $post["pro_id"]);
                 // 						if($row_get){
                 // 							$data_update = array(
                 // 									"qty_order" => $row_get["qty_order"]-$post["qty_order"],
                 // 							);
                 // 							$db_global->updateRecord($data_update,$row_get["id"],"id","tb_purchase_order_item_tmp");
                 // 							unset($data_update);
                 // 						}
                 // 						$rows_stock=$db_global->InventoryExist($post["pro_id"]);
                 // 						if($rows_stock){
                 // 							$dataInventory= array(
                 // 									'QuantityOnHand'    => $rows_stock["QuantityOnHand"]+ $post["qty_order"],
                 // 									'QuantityOnOrder'   => $rows_stock["QuantityOnOrder"]- $post["qty_order"],
                 // 									'QuantityAvailable' => $rows_stock["QuantityAvailable"]+$post["qty_order"],
                 // 									'Timestamp'         => new Zend_date()
                 // 							);
                 // 							$db_global->updateRecord($dataInventory,$rows_stock["ProdId"],"ProdId","tb_inventorytotal");
                 // 							unset($dataInventory);
                 //     					}
                 // 						else{
                 // 							$addInventory= array(
                 // 									'ProdId'            => $post["pro_id"],
                 // 									'QuantityOnHand'    => $post["qty_order"],
                 // 									'QuantityAvailable' => $post["qty_order"],
                 // 									'Timestamp'         => new Zend_date()
                 // 							);
                 // 							$db->insert("tb_inventorytotal", $addInventory);
                 // 							unset($addInventory);
                 // 						}
             }
         }
     }
 }