|
|
@@ -8,6 +8,7 @@ use biz\shop\classes\ShopClass;
|
|
|
use biz\stat\classes\StatCgClass;
|
|
|
use biz\stat\classes\StatOutClass;
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
+use bizGhs\custom\classes\CustomClass;
|
|
|
use bizGhs\order\traits\OrderTrait;
|
|
|
use bizGhs\stock\services\StockRecordService;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
@@ -34,6 +35,10 @@ class PurchaseOrderClass extends BaseClass
|
|
|
self::PURCHASE_ORDER_STATUS_COMPLETE => '已完成',
|
|
|
];
|
|
|
|
|
|
+ const DEBT_UNKNOWN = 0;
|
|
|
+ const DEBT_YES = 1;
|
|
|
+ const DEBT_NO = 2;
|
|
|
+
|
|
|
//添加采购单 lqh 2021.1.19
|
|
|
public static function addOrder($data)
|
|
|
{
|
|
|
@@ -57,8 +62,12 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$smallNum += $v['smallNum'] ?? 0;
|
|
|
$totalItemPrice = bcadd($totalItemPrice, $v['itemPrice'], 2);
|
|
|
$ghsItemInfoMap[$v['productId']] = $v;
|
|
|
- $weight = $v['weight']??0;
|
|
|
- $totalItemWeight = bcadd($totalItemWeight,$weight,2);
|
|
|
+ if (getenv('YII_ENV', 'local') == 'production') {
|
|
|
+ $weight = $v['weight'] ?? 0;
|
|
|
+ } else {
|
|
|
+ $weight = 0.6;
|
|
|
+ }
|
|
|
+ $totalItemWeight = bcadd($totalItemWeight, $weight, 2);
|
|
|
}
|
|
|
}
|
|
|
$data['bigNum'] = $bigNum;
|
|
|
@@ -86,6 +95,9 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$orderPrice = bcadd($orderPrice, $pickCharge, 2);
|
|
|
$orderPrice = bcadd($orderPrice, $localCharge, 2);
|
|
|
$data['orderPrice'] = $orderPrice;
|
|
|
+ $data['prePrice'] = $orderPrice;
|
|
|
+ $data['actPrice'] = $orderPrice;
|
|
|
+ $data['realPrice'] = $orderPrice;
|
|
|
|
|
|
//总运费
|
|
|
$totalFreight = bcadd($packingCharge, $shortCharge, 2);
|
|
|
@@ -93,6 +105,10 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$totalFreight = bcadd($totalFreight, $pickCharge, 2);
|
|
|
$totalFreight = bcadd($totalFreight, $localCharge, 2);
|
|
|
|
|
|
+ if ($totalFreight <= 0) {
|
|
|
+ util::fail('请填写运费');
|
|
|
+ }
|
|
|
+
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
|
|
|
@@ -112,11 +128,12 @@ class PurchaseOrderClass extends BaseClass
|
|
|
foreach ($batchData as $v) {
|
|
|
$totalItemNum = bcadd($totalItemNum, $v['itemNum'], 2);
|
|
|
}
|
|
|
+
|
|
|
//平均计算出每扎得运费:总运费/总扎数
|
|
|
- $avgFreight = bcdiv($totalFreight, $totalItemNum, 2);
|
|
|
+ //$avgFreight = bcdiv($totalFreight, $totalItemNum, 2);
|
|
|
|
|
|
- //计算每g的运费 总运费/总重量
|
|
|
- $avgFreightByWeight = bcdiv($totalFreight, $totalItemWeight*1000, 2);
|
|
|
+ //计算每公斤的运费 总运费/总重量
|
|
|
+ $avgKgWeight = bcdiv($totalFreight, $totalItemWeight, 2);
|
|
|
|
|
|
//现在暂时点击确定,完成 加库存
|
|
|
foreach ($batchData as $v) {
|
|
|
@@ -144,11 +161,11 @@ class PurchaseOrderClass extends BaseClass
|
|
|
// 每扎采购价+每扎运费 = 每扎成本价
|
|
|
//$avgCost = bcadd($avgItemCost, $avgFreight, 2);
|
|
|
//2021-06-11 修改每扎运费计算
|
|
|
- $itemInfoTmp = json_decode($v['itemInfo'],true);
|
|
|
+ $itemInfoTmp = json_decode($v['itemInfo'], true);
|
|
|
//花材的重量
|
|
|
- $productWeight = $itemInfoTmp['itemWeight']??0;
|
|
|
- $avgWeighFreight = bcmul($avgFreightByWeight,$productWeight*1000,2);
|
|
|
- $avgCost = bcadd($avgItemCost, $avgWeighFreight, 2);
|
|
|
+ $productWeight = $itemInfoTmp['itemWeight'] ?? 0;
|
|
|
+ $productFreight = bcmul($avgKgWeight, $productWeight, 2);
|
|
|
+ $avgCost = bcadd($avgItemCost, $productFreight, 2);
|
|
|
//修改 ghsItem 中的成本价
|
|
|
// ItemClass::changeCost($itemId,$sjId,$avgCost);
|
|
|
|
|
|
@@ -156,7 +173,6 @@ class PurchaseOrderClass extends BaseClass
|
|
|
ProductClass::changeCost($productId, $avgCost);
|
|
|
//触发自动调价 2021.4.26 linqh
|
|
|
ProductClass::autoPriceById($productId);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//门店支出增加
|
|
|
@@ -177,6 +193,32 @@ class PurchaseOrderClass extends BaseClass
|
|
|
//当天和当月支出统计
|
|
|
StatOutClass::updateOrInsert($shop, $order['orderPrice']);
|
|
|
|
|
|
+ //供货商资产增加
|
|
|
+ $ghsId = $data['ghsId'] ?? 0;
|
|
|
+ $ghs = GhsClass::getLockById($ghsId);
|
|
|
+ if (empty($ghs)) {
|
|
|
+ util::fail('没有找到供货商');
|
|
|
+ }
|
|
|
+ $ghs->debt = GhsClass::DEBT_YES;
|
|
|
+ $ghs->debtAmount = bcadd($ghs->debtAmount, $order['orderPrice'], 2);
|
|
|
+ $ghs->debtNum += 1;
|
|
|
+ $ghs->expendAmount = bcadd($ghs->expendAmount, $order['orderPrice'], 2);
|
|
|
+ $ghs->expendNum += 1;
|
|
|
+ $ghs->save();
|
|
|
+
|
|
|
+ //客户资产增加
|
|
|
+ $customId = $ghs->customId;
|
|
|
+ $custom = CustomClass::getLockById($customId);
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('没有找到客户信息');
|
|
|
+ }
|
|
|
+ $custom->isDebt = CustomClass::IS_DEBT_YES;
|
|
|
+ $custom->debtAmount = bcadd($custom->debtAmount, $order['orderPrice'], 2);
|
|
|
+ $custom->debtNum += 1;
|
|
|
+ $custom->buyNum += 1;
|
|
|
+ $custom->buyAmount = bcadd($custom->buyAmount, $order['orderPrice'], 2);
|
|
|
+ $custom->save();
|
|
|
+
|
|
|
//支出流水
|
|
|
$payWay = dict::getDict('payWay', 'unknown');
|
|
|
$capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
|
|
|
@@ -292,8 +334,8 @@ class PurchaseOrderClass extends BaseClass
|
|
|
'rank' => $rank,// 花材级别
|
|
|
'bigUnit' => $productData[$productId]['bigUnit'],//大单位名称 扎
|
|
|
'smallUnit' => $productData[$productId]['smallUnit'],//小单位名称 支
|
|
|
- 'purchaseWeight' => $v['weight']??0, //采购重量
|
|
|
- 'itemWeight'=>$productData[$productId]['weight']??0,
|
|
|
+ 'purchaseWeight' => $v['weight'] ?? 0, //采购重量
|
|
|
+ 'itemWeight' => $productData[$productId]['weight'] ?? 0,
|
|
|
];
|
|
|
$tmp['itemInfo'] = json_encode($itemInfo);
|
|
|
$batchData[] = $tmp;
|