if ($action == 'addLocationMany') { //------------------------------------------------------ $inboundID = $_POST['inboundID']; $poID = $_POST['poID']; $sqlLocationID = $db->get_where('tb_address', array('add_name' => $_POST['locationID'])); $rsLocationID = $sqlLocationID->row_array(); $locationID = $rsLocationID['add_id']; // get location ID foreach ($inboundID as $key => $val) { $sqlInbound = $db->get_where('inbound_po', array('inbound_id' => $val)); $rsInbound = $sqlInbound->row_array(); $data = array('inbound_id' => $val, 'location_id' => $locationID, 'qty' => $rsInbound['product_qty'], 'qty_remain' => $rsInbound['product_qty'], 'time' => _DATE_TIME_, 'update_time' => _DATE_TIME_, 'user_id' => $userID); if ($db->insert('inbound_location', $data)) { insert_tb_stock_product($rsInbound['product_no'], $rsInbound['product_name'], $rsInbound['product_unit'], $rsInbound['product_qty'], $userID); $db->update('inbound_po', array('product_date_in' => _DATE_TIME_, 'po_status' => 1), array('inbound_id' => $val)); checkStatusInbound($poID); } } } else { if ($action == 'choiceCar') { $carID = $_POST['carID']; $rtID = $_POST['rtID']; // 17-09-2558 $time = strtotime("now"); $date = date('Ymd'); foreach ($rtID as $key => $val) { $data = array('car_id' => $carID, 'outbound_rt' => $val, 'user_id' => $userID, 'date_time' => _DATE_TIME_, 'organize_truck_id' => $date . $time); $db->insert('outbound_car', $data); $dataStatus = array('status' => 4, 'update_time' => _DATE_TIME_, 'user_id' => $userID); $db->update('outbound_rt_status', $dataStatus, array('rt_id' => $val)); }
//ยืนยันสินค้าในพาเลทนี้เก็บเข้า location แล้ว $db->update('inbound_pallet_item', array('status' => 1), array('inbound_key' => $inboundKey, 'pallet_id' => $palletID)); $db->select('product_qty,po_id'); $sqlGetIn = $db->get_where('inbound_po', array('inbound_id' => $inboundKey)); $rsGetIn = $sqlGetIn->row_array(); // ดึงจำนวนที่รับเข้า $db->select('SUM(qty) as qty'); $sqlNumIn = $db->get_where('inbound_location', array('inbound_id' => $inboundKey)); $rsNumIn = $sqlNumIn->row_array(); // ดึงจำนวนสินค้านั้นๆ ของ po นั้นๆ ที่ได้นำเข้าตำแหน่งแล้ว //เช็คจำนวน ที่รับเข้า กับ จำนวนที่เก็บในคลัง เท่ากันหรือไม่ เพื่อ ยืนยันสถานะว่าเก็บเข้าคลังเรียบร้อย if ($rsGetIn['product_qty'] == $rsNumIn['qty'] && $rsGetIn['product_qty'] != 0) { //เปลี่ยน status เก็บเข้าที่แล้ว $db->edit('inbound_po', array('dateupdate' => _DATE_TIME_, 'po_status' => 2, 'user_update' => $userID), array('inbound_id' => $inboundKey)); //echo 'udate inbound_po status = 2 ]]]]'.$db->last_query(); checkStatusInbound($rsGetIn['po_id']); } } } checkPalletStatus($palletID); } } header('location:' . $actionBack); function checkPalletStatus($palletID) { $db = DB(); $sqlGetItem = $db->get_where('inbound_pallet_item', array('pallet_id' => $palletID, 'status !=' => 1)); $rsStatus = $sqlGetItem->num_rows(); if ($rsStatus == 0) { $db->update('inbound_pallet', array('pallet_status' => 2, 'put_time' => _DATE_TIME_, 'user_put' => $userID), array('pallet_id' => $palletID)); }
$mainPO[] = $val['PO_ID']; } //$test = array_unique($mainPO, SORT_REGULAR); //echo count($test); //print_r($test); foreach ($data as $array) { if ($array['cstatus'] == 0 && $array['istatus'] == 0) { $sqlIbp = $db->get_where('inbound_po', array('po_id' => $array['PO_ID'], 'product_no' => $array['GOODCODE_PO'], 'ibp_id' => '')); $rowIbp = $sqlIbp->num_rows(); //echo $db->last_query(); if ($rowIbp == 1) { $dataUpdatePO = array('ibp_id' => $array['DOC_IBP'], 'product_qty' => (int) $array['PO_QTY'], 'po_status' => 1, 'free_qty' => (int) $array['IBP_QTY_FEE'], 'product_date_in' => _DATE_TIME_, 'user_update' => $user_id, 'dateupdate' => _DATE_TIME_); $sqlEditPo = $db->edit('inbound_po', $dataUpdatePO, array('po_id' => $array['PO_ID'], 'product_no' => $array['GOODCODE_PO'])); //echo $db->last_query(); insert_tb_stock_product($array['GOODCODE_PO'], $array['GOOD_IBP_ALIAS'], $array['PO_UTQ'], (int) $array['PO_QTY'], $user_id); checkStatusInbound($array['PO_ID'], $array['DOC_IBP']); $success = 1; } else { $sqlIbp = $db->get_where('inbound_po', array('po_id' => $array['PO_ID'], 'product_no' => $array['GOODCODE_PO'], 'ibp_id !=' => $array['DOC_IBP'])); $rowIbp = $sqlIbp->num_rows(); $value = $sqlIbp->row_array(); if ($rowIbp > 0) { $inbound_po_fields = array('po_id' => $value['po_id'], 'ibp_id' => $array['DOC_IBP'], 'receipt_type' => $value['receipt_type'], 'po_create' => $value['po_create'], 'po_delivery_date' => $value['po_delivery_date'], 'po_supplier' => $value['po_supplier'], 'product_no' => $value['product_no'], 'product_name' => $value['product_name'], 'cat' => $value['cat'], 'order_qty' => $value['order_qty'], 'product_qty' => (int) $array['PO_QTY'], 'free_qty' => (int) $array['IBP_QTY_FEE'], 'product_unit' => $value['product_unit'], 'product_date_in' => _DATE_TIME_, 'product_create_date' => $value['po_create'], 'product_fefo' => $value['product_fefo'], 'product_fefo_date' => $value['product_fefo_date'], 'user_create' => $value['user_create'], 'user_update' => $user_id, 'note' => $value['note'], 'po_status' => 1, 'datecreate' => $value['datecreate'], 'dateupdate' => _DATE_TIME_, 'status' => strtolower($value[12]) == 'active' ? 0 : 1); $db->insert('inbound_po', $inbound_po_fields); insert_tb_stock_product($array['GOODCODE_PO'], $array['GOOD_IBP_ALIAS'], $array['PO_UTQ'], (int) $array['PO_QTY'], $user_id); $sqlChkStatus = $db->get_where('inbound_status', array('inbound_id' => $value['po_id'], 'ibp_id' => $array['DOC_IBP'])); $rowChkStatus = $sqlChkStatus->num_rows(); $inbound_status_fields = array('inbound_id' => $value['po_id'], 'ibp_id' => $array['DOC_IBP'], 'start_date' => _DATE_TIME_, 'status' => 1, 'time_get_product' => _DATE_TIME_, 'time_in_stock' => 0); $db->insert('inbound_status', $inbound_status_fields); $success = 1; }