fix:depot_purchase
This commit is contained in:
@@ -29,8 +29,8 @@ class DepotRequest extends FormRequest
|
|||||||
'city_id' => 'required|integer|exists:system_city,id',
|
'city_id' => 'required|integer|exists:system_city,id',
|
||||||
'kitchen_id' => 'required|integer|exists:kitchen,id',
|
'kitchen_id' => 'required|integer|exists:kitchen,id',
|
||||||
'id' => 'required|integer',
|
'id' => 'required|integer',
|
||||||
'purchase_price' => 'required',
|
'purchase_price' => 'required|numeric',
|
||||||
'number' => 'required',
|
'number' => 'required|numeric',
|
||||||
'depot_id' => 'required|integer|exists:depot,id',
|
'depot_id' => 'required|integer|exists:depot,id',
|
||||||
'material_id' => 'required|integer|exists:material,id',
|
'material_id' => 'required|integer|exists:material,id',
|
||||||
'supplier_id' => 'required|integer|exists:supplier,id',
|
'supplier_id' => 'required|integer|exists:supplier,id',
|
||||||
|
|||||||
@@ -149,11 +149,11 @@ class DepotService extends BaseService{
|
|||||||
$materialId = (int)$this->request->input('material_id');
|
$materialId = (int)$this->request->input('material_id');
|
||||||
$supplierId = (int)$this->request->input('supplier_id');
|
$supplierId = (int)$this->request->input('supplier_id');
|
||||||
|
|
||||||
$purchase_price = (double)$this->request->input('purchase_price');
|
$purchase_price = $this->request->input('purchase_price');
|
||||||
$number = (double)$this->request->input('number');
|
$number = $this->request->input('number');
|
||||||
|
|
||||||
if (!empty($purchase_price) && !empty($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');
|
$cityId = (int)$this->request->input('city_id');
|
||||||
@@ -188,9 +188,10 @@ class DepotService extends BaseService{
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//库存增加
|
//库存增加
|
||||||
$totalValue = $purchase_price * $number + $materialStock->unit_price * $materialStock->current_stock;
|
// $totalValue = bcadd(bcmul($purchase_price,$number),bcmul($materialStock->unit_price,$materialStock->current_stock),2);
|
||||||
$materialStock->current_stock = $materialStock->current_stock + $number;
|
$materialStock->current_stock = bcadd($materialStock->current_stock,$number,2);
|
||||||
$materialStock->unit_price = $totalValue/$materialStock->current_stock;
|
// $materialStock->unit_price = bcdiv($totalValue,$materialStock->current_stock,2);
|
||||||
|
$materialStock->unit_price = $purchase_price;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败');
|
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败');
|
||||||
@@ -239,17 +240,19 @@ class DepotService extends BaseService{
|
|||||||
|
|
||||||
public function purchaseBack():array
|
public function purchaseBack():array
|
||||||
{
|
{
|
||||||
$id = (int)$this->request->input('id');
|
Db::beginTransaction();
|
||||||
|
try {
|
||||||
|
$id = (int)$this->request->input('id');
|
||||||
// $number = (double)$this->request->input('number');
|
// $number = (double)$this->request->input('number');
|
||||||
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
||||||
$info->status = DepotCode::OUTPUT;
|
$info->status = DepotCode::OUTPUT;
|
||||||
if (!empty($info)){
|
if (!empty($info)){
|
||||||
$depotPurchase = new DepotPurchase();
|
$depotPurchase = new DepotPurchase();
|
||||||
$depotPurchase->depot_id = $info->depot_id;
|
$depotPurchase->depot_id = $info->depot_id;
|
||||||
$depotPurchase->material_id = $info->material_id;
|
$depotPurchase->material_id = $info->material_id;
|
||||||
$depotPurchase->supplier_id = $info->supplier_id;
|
$depotPurchase->supplier_id = $info->supplier_id;
|
||||||
$depotPurchase->type = 2;
|
$depotPurchase->type = 2;
|
||||||
$depotPurchase->purchase_price = $info->purchase_price;
|
$depotPurchase->purchase_price = $info->purchase_price;
|
||||||
// if (empty($number)){
|
// if (empty($number)){
|
||||||
$depotPurchase->number = $info->number;
|
$depotPurchase->number = $info->number;
|
||||||
// }
|
// }
|
||||||
@@ -260,27 +263,33 @@ class DepotService extends BaseService{
|
|||||||
// throw new ErrException('采购退货数量不能大于进货数量');
|
// throw new ErrException('采购退货数量不能大于进货数量');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number;
|
$depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number;
|
||||||
$depotPurchase->city_id = $info->city_id;
|
$depotPurchase->city_id = $info->city_id;
|
||||||
$depotPurchase->kitchen_id = $info->kitchen_id;
|
$depotPurchase->kitchen_id = $info->kitchen_id;
|
||||||
$depotPurchase->operator_id = $this->adminId;
|
$depotPurchase->operator_id = $this->adminId;
|
||||||
}
|
}
|
||||||
|
|
||||||
$materialStock = $this->MaterialStockModel
|
$materialStock = $this->MaterialStockModel
|
||||||
->where('depot_id',$depotPurchase->depot_id)
|
->where('depot_id',$depotPurchase->depot_id)
|
||||||
->where('material_id',$depotPurchase->material_id)
|
->where('material_id',$depotPurchase->material_id)
|
||||||
->where('supplier_id',$depotPurchase->supplier_id)
|
->where('supplier_id',$depotPurchase->supplier_id)
|
||||||
->first();
|
->first();
|
||||||
if (empty($materialStock))
|
if (empty($materialStock))
|
||||||
throw new ErrException('库存更改异常');
|
throw new ErrException('库存更改异常');
|
||||||
else{
|
else{
|
||||||
if ($materialStock->current_stock < $depotPurchase->number)
|
if ($materialStock->current_stock < $depotPurchase->number)
|
||||||
throw new ErrException('库存数量小于退货数量');
|
throw new ErrException('库存数量小于退货数量');
|
||||||
//库存减少
|
//库存减少
|
||||||
$materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number;
|
$materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常');
|
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();
|
return $this->return->success();
|
||||||
}
|
}
|
||||||
@@ -365,50 +374,58 @@ class DepotService extends BaseService{
|
|||||||
|
|
||||||
public function depotSale():array
|
public function depotSale():array
|
||||||
{
|
{
|
||||||
$depotId = (int)$this->request->input('depot_id');
|
Db::beginTransaction();
|
||||||
$materialId = (int)$this->request->input('material_id');
|
try {
|
||||||
$supplierId = (int)$this->request->input('supplier_id');
|
$depotId = (int)$this->request->input('depot_id');
|
||||||
$number = (double)$this->request->input('number');
|
$materialId = (int)$this->request->input('material_id');
|
||||||
$applicationId = (int)$this->request->input('application_id');
|
$supplierId = (int)$this->request->input('supplier_id');
|
||||||
$cityId = (int)$this->request->input('city_id');
|
$number = (double)$this->request->input('number');
|
||||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
$applicationId = (int)$this->request->input('application_id');
|
||||||
|
$cityId = (int)$this->request->input('city_id');
|
||||||
|
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||||
|
|
||||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
throw new ErrException('该角色没有权限');
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
$applicationInfo = $this->MaterialApplicationModel
|
$applicationInfo = $this->MaterialApplicationModel
|
||||||
->where('id',$applicationId)
|
->where('id',$applicationId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$materialStock = $this->MaterialStockModel
|
$materialStock = $this->MaterialStockModel
|
||||||
->where('depot_id',$depotId)
|
->where('depot_id',$depotId)
|
||||||
->where('material_id',$materialId)
|
->where('material_id',$materialId)
|
||||||
->where('supplier_id',$supplierId)
|
->where('supplier_id',$supplierId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$depotSale = new DepotSale();
|
$depotSale = new DepotSale();
|
||||||
$depotSale->depot_id = $depotId;
|
$depotSale->depot_id = $depotId;
|
||||||
$depotSale->dish_id = $applicationInfo->dish_id;
|
$depotSale->dish_id = $applicationInfo->dish_id;
|
||||||
$depotSale->material_id = $materialId;
|
$depotSale->material_id = $materialId;
|
||||||
$depotSale->supplier_id = $supplierId;
|
$depotSale->supplier_id = $supplierId;
|
||||||
$depotSale->sale_price = $materialStock->unit_price;
|
$depotSale->sale_price = $materialStock->unit_price;
|
||||||
$depotSale->number = $number;
|
$depotSale->number = $number;
|
||||||
$depotSale->sum_price = $depotSale->sale_price * $number;
|
$depotSale->sum_price = $depotSale->sale_price * $number;
|
||||||
$depotSale->application_id = $applicationId;
|
$depotSale->application_id = $applicationId;
|
||||||
$depotSale->city_id = $cityId;
|
$depotSale->city_id = $cityId;
|
||||||
$depotSale->kitchen_id = $kitchenId;
|
$depotSale->kitchen_id = $kitchenId;
|
||||||
$depotSale->operator_id = $this->adminId;
|
$depotSale->operator_id = $this->adminId;
|
||||||
|
|
||||||
//库存减少
|
//库存减少
|
||||||
$materialStock->current_stock = $materialStock->current_stock - $number;
|
$materialStock->current_stock = $materialStock->current_stock - $number;
|
||||||
|
|
||||||
$applicationInfo->al_number = $number + $applicationInfo->al_number;
|
$applicationInfo->al_number = $number + $applicationInfo->al_number;
|
||||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||||
else
|
else
|
||||||
$applicationInfo->status = MaterialCode::ALL_OUT;
|
$applicationInfo->status = MaterialCode::ALL_OUT;
|
||||||
|
|
||||||
if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常');
|
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();
|
return $this->return->success();
|
||||||
|
|
||||||
@@ -416,78 +433,94 @@ class DepotService extends BaseService{
|
|||||||
|
|
||||||
public function saleUpdate():array
|
public function saleUpdate():array
|
||||||
{
|
{
|
||||||
$id = (int)$this->request->input('id');
|
Db::beginTransaction();
|
||||||
|
try {
|
||||||
|
$id = (int)$this->request->input('id');
|
||||||
|
|
||||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
throw new ErrException('该角色没有权限');
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
$info = $this->DepotSaleModel
|
$info = $this->DepotSaleModel
|
||||||
->where('id',$id)
|
->where('id',$id)
|
||||||
->first();
|
->first();
|
||||||
$applicationInfo = $this->MaterialApplicationModel
|
$applicationInfo = $this->MaterialApplicationModel
|
||||||
->where('id',$info->application_id)
|
->where('id',$info->application_id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$old_number = $info->number;
|
$old_number = $info->number;
|
||||||
|
|
||||||
$number = (double)$this->request->input('number');
|
$number = (double)$this->request->input('number');
|
||||||
$sum_price = $info->sale_price * $number;
|
$sum_price = $info->sale_price * $number;
|
||||||
|
|
||||||
$info->number = $number;
|
$info->number = $number;
|
||||||
$info->sum_price = $sum_price;
|
$info->sum_price = $sum_price;
|
||||||
|
|
||||||
$materialStock = $this->MaterialStockModel
|
$materialStock = $this->MaterialStockModel
|
||||||
->where('depot_id',$info->depot_id)
|
->where('depot_id',$info->depot_id)
|
||||||
->where('material_id',$info->material_id)
|
->where('material_id',$info->material_id)
|
||||||
->where('supplier_id',$info->supplier_id)
|
->where('supplier_id',$info->supplier_id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$materialStock->current_stock = $materialStock->current_stock + $old_number - $number;
|
$materialStock->current_stock = $materialStock->current_stock + $old_number - $number;
|
||||||
|
|
||||||
$applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number;
|
$applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number;
|
||||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||||
else
|
else
|
||||||
$applicationInfo->status = MaterialCode::ALL_OUT;
|
$applicationInfo->status = MaterialCode::ALL_OUT;
|
||||||
|
|
||||||
if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败');
|
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();
|
return $this->return->success();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saleDelete():array
|
public function saleDelete():array
|
||||||
{
|
{
|
||||||
$id = (int)$this->request->input('id');
|
Db::beginTransaction();
|
||||||
|
try {
|
||||||
|
$id = (int)$this->request->input('id');
|
||||||
|
|
||||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
throw new ErrException('该角色没有权限');
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
$info = $this->DepotSaleModel
|
$info = $this->DepotSaleModel
|
||||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||||
->where('id',$id)
|
->where('id',$id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$applicationInfo = $this->MaterialApplicationModel
|
$applicationInfo = $this->MaterialApplicationModel
|
||||||
->where('id',$info->application_id)
|
->where('id',$info->application_id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$applicationInfo->al_number = $applicationInfo->al_number - $info->number;
|
$applicationInfo->al_number = $applicationInfo->al_number - $info->number;
|
||||||
if ($applicationInfo->al_number <= 0)
|
if ($applicationInfo->al_number <= 0)
|
||||||
$applicationInfo->status = MaterialCode::AUDITED;
|
$applicationInfo->status = MaterialCode::AUDITED;
|
||||||
else if ($applicationInfo->al_number < $applicationInfo->number)
|
else if ($applicationInfo->al_number < $applicationInfo->number)
|
||||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||||
|
|
||||||
$materialStock = $this->MaterialStockModel
|
$materialStock = $this->MaterialStockModel
|
||||||
->where('depot_id',$info->depot_id)
|
->where('depot_id',$info->depot_id)
|
||||||
->where('material_id',$info->material_id)
|
->where('material_id',$info->material_id)
|
||||||
->where('supplier_id',$info->supplier_id)
|
->where('supplier_id',$info->supplier_id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$materialStock->current_stock = $materialStock->current_stock + $info->number;
|
$materialStock->current_stock = $materialStock->current_stock + $info->number;
|
||||||
|
|
||||||
$info->is_del = MaterialCode::IS_DEL;
|
$info->is_del = MaterialCode::IS_DEL;
|
||||||
|
|
||||||
if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败');
|
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();
|
return $this->return->success();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user