fix:depot_purchase
This commit is contained in:
@@ -29,8 +29,8 @@ class DepotRequest extends FormRequest
|
||||
'city_id' => 'required|integer|exists:system_city,id',
|
||||
'kitchen_id' => 'required|integer|exists:kitchen,id',
|
||||
'id' => 'required|integer',
|
||||
'purchase_price' => 'required',
|
||||
'number' => 'required',
|
||||
'purchase_price' => 'required|numeric',
|
||||
'number' => 'required|numeric',
|
||||
'depot_id' => 'required|integer|exists:depot,id',
|
||||
'material_id' => 'required|integer|exists:material,id',
|
||||
'supplier_id' => 'required|integer|exists:supplier,id',
|
||||
|
||||
@@ -149,11 +149,11 @@ class DepotService extends BaseService{
|
||||
$materialId = (int)$this->request->input('material_id');
|
||||
$supplierId = (int)$this->request->input('supplier_id');
|
||||
|
||||
$purchase_price = (double)$this->request->input('purchase_price');
|
||||
$number = (double)$this->request->input('number');
|
||||
$purchase_price = $this->request->input('purchase_price');
|
||||
$number = $this->request->input('number');
|
||||
|
||||
if (!empty($purchase_price) && !empty($number)){
|
||||
$sum_price = $purchase_price * $number;
|
||||
$sum_price = bcmul($purchase_price,$number);
|
||||
}
|
||||
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
@@ -188,9 +188,10 @@ class DepotService extends BaseService{
|
||||
}
|
||||
else{
|
||||
//库存增加
|
||||
$totalValue = $purchase_price * $number + $materialStock->unit_price * $materialStock->current_stock;
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number;
|
||||
$materialStock->unit_price = $totalValue/$materialStock->current_stock;
|
||||
// $totalValue = bcadd(bcmul($purchase_price,$number),bcmul($materialStock->unit_price,$materialStock->current_stock),2);
|
||||
$materialStock->current_stock = bcadd($materialStock->current_stock,$number,2);
|
||||
// $materialStock->unit_price = bcdiv($totalValue,$materialStock->current_stock,2);
|
||||
$materialStock->unit_price = $purchase_price;
|
||||
}
|
||||
|
||||
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败');
|
||||
@@ -239,6 +240,8 @@ class DepotService extends BaseService{
|
||||
|
||||
public function purchaseBack():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
// $number = (double)$this->request->input('number');
|
||||
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
||||
@@ -282,6 +285,12 @@ class DepotService extends BaseService{
|
||||
|
||||
if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
@@ -365,6 +374,8 @@ class DepotService extends BaseService{
|
||||
|
||||
public function depotSale():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$depotId = (int)$this->request->input('depot_id');
|
||||
$materialId = (int)$this->request->input('material_id');
|
||||
$supplierId = (int)$this->request->input('supplier_id');
|
||||
@@ -410,12 +421,20 @@ class DepotService extends BaseService{
|
||||
|
||||
if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function saleUpdate():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
@@ -452,11 +471,19 @@ class DepotService extends BaseService{
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function saleDelete():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
@@ -489,6 +516,12 @@ class DepotService extends BaseService{
|
||||
|
||||
if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user