Esempio n. 1
0
 public function act_pdaAdjust()
 {
     $userCnName = $_SESSION['userCnName'];
     $userId = $_SESSION['userId'];
     $groupid = trim($_POST['groupid']);
     $num = intval(trim($_POST['num']));
     if ($num == 0) {
         self::$errCode = "401";
         self::$errMsg = "请输入正数";
         return false;
     }
     $list = packageCheckModel::getSKUByGroupId($groupid);
     if ($list) {
         OmAvailableModel::begin();
         $entryStatus = 0;
         $nums = -$num;
         $id = $list[0]['id'];
         $batchNum = $list[0]['batchNum'];
         $sku = $list[0]['sku'];
         $beforeNum = $list[0]['num'];
         $ichibanNums = $list[0]['ichibanNums'];
         $shelvesNums = $list[0]['shelvesNums'];
         $now_num = $beforeNum - $num;
         $u_num = -$num;
         /** 判断点货调整后数量是否为负数**/
         if ($now_num <= 0) {
             self::$errCode = 203;
             self::$errMsg = "调整后数量必须大于0!";
             return false;
         }
         /** 已上架情况下不许调整**/
         if ($shelvesNums) {
             self::$errCode = 203;
             self::$errMsg = "料号已有上架数,不能调整!";
             return false;
         }
         /** 判断有良品的情况下调整数量只能小于原先点货数量**/
         if ($ichibanNums && $now_num > $beforeNum) {
             self::$errCode = 203;
             self::$errMsg = "良品存在时,点货调整后数量必须小于原点货数量!";
             return false;
         }
         CommonModel::adjustPrintNum($batchNum, $nums);
         //去除qc数量
         if ($shelvesNums == 0) {
             //释放采购hold住数量
             $delCheckOnWaySku = CommonModel::checkOnWaySkuNum($sku, $beforeNum, 2);
             //验证sku在途数量是否足够
             $checkOnWaySku = CommonModel::checkOnWaySkuNum($sku, $now_num, 1);
             if ($checkOnWaySku == 0) {
                 $u_num = -$num;
             } else {
                 $entryStatus = 1;
                 $u_num = -$beforeNum;
             }
         }
         $updateinfo = packageCheckModel::updateRecord($id, $nums, $entryStatus);
         if (!$updateinfo) {
             self::$errCode = 203;
             self::$errMsg = "更新点货记录失败!";
             OmAvailableModel::rollback();
             return false;
         }
         $insertinfo = packageCheckModel::insertAdjustRecord($id, $nums, $beforeNum, $userId);
         if (!$insertinfo) {
             self::$errCode = 204;
             self::$errMsg = "插入点货调整记录失败!";
             OmAvailableModel::rollback();
             return false;
         }
         $updatestore = packageCheckModel::updateStore($sku, $u_num);
         if (!updatestore) {
             self::$errCode = 205;
             self::$errMsg = "更新总库存失败!";
             OmAvailableModel::rollback();
             return false;
         }
         if ($ichibanNums != 0 && $ichibanNums != NULL) {
             $updateIchibanNums = packageCheckModel::updateIchibanNums($nums, $id);
             if ($shelvesNums != 0) {
                 $updateshelvesNums = packageCheckModel::updateShelvesNums($nums, $sku, $id);
                 if (!$updateshelvesNums) {
                     self::$errCode = 206;
                     self::$errMsg = "更新上架库存失败!";
                     OmAvailableModel::rollback();
                     return false;
                 }
                 $update_onhand = CommonModel::adjustOut($sku, $nums, $userCnName);
                 if ($update_onhand == 0) {
                     self::$errCode = 206;
                     self::$errMsg = "更新旧erp库存失败";
                     OmAvailableModel::rollback();
                     return false;
                 }
             }
         }
         self::$errMsg = "调整成功";
         OmAvailableModel::commit();
         return true;
     } else {
         self::$errCode = "402";
         self::$errMsg = "该分组不存在";
         return false;
     }
 }