mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE): enhance product warehouse handling and automatic calculations for delivery and sales orders
This commit is contained in:
@@ -247,11 +247,15 @@ func (s *deliveryOrdersService) CreateOne(c *fiber.Ctx, req *validation.Delivery
|
||||
itemDeliveryDate = &parsedDate
|
||||
}
|
||||
|
||||
// Hitung total_weight dan total_price otomatis
|
||||
totalWeight := requestedProduct.Qty * requestedProduct.AvgWeight
|
||||
totalPrice := requestedProduct.UnitPrice * requestedProduct.Qty
|
||||
|
||||
deliveryProduct.ProductWarehouseId = foundMarketingProduct.ProductWarehouseId
|
||||
deliveryProduct.UnitPrice = requestedProduct.UnitPrice
|
||||
deliveryProduct.AvgWeight = requestedProduct.AvgWeight
|
||||
deliveryProduct.TotalWeight = requestedProduct.TotalWeight
|
||||
deliveryProduct.TotalPrice = requestedProduct.TotalPrice
|
||||
deliveryProduct.TotalWeight = totalWeight
|
||||
deliveryProduct.TotalPrice = totalPrice
|
||||
deliveryProduct.DeliveryDate = itemDeliveryDate
|
||||
deliveryProduct.VehicleNumber = requestedProduct.VehicleNumber
|
||||
|
||||
@@ -357,11 +361,15 @@ func (s deliveryOrdersService) UpdateOne(c *fiber.Ctx, req *validation.DeliveryO
|
||||
|
||||
oldRequestedQty := deliveryProduct.UsageQty + deliveryProduct.PendingQty
|
||||
|
||||
// Hitung total_weight dan total_price otomatis
|
||||
totalWeight := requestedProduct.Qty * requestedProduct.AvgWeight
|
||||
totalPrice := requestedProduct.UnitPrice * requestedProduct.Qty
|
||||
|
||||
deliveryProduct.ProductWarehouseId = foundMarketingProduct.ProductWarehouseId
|
||||
deliveryProduct.UnitPrice = requestedProduct.UnitPrice
|
||||
deliveryProduct.AvgWeight = requestedProduct.AvgWeight
|
||||
deliveryProduct.TotalWeight = requestedProduct.TotalWeight
|
||||
deliveryProduct.TotalPrice = requestedProduct.TotalPrice
|
||||
deliveryProduct.TotalWeight = totalWeight
|
||||
deliveryProduct.TotalPrice = totalPrice
|
||||
deliveryProduct.DeliveryDate = itemDeliveryDate
|
||||
deliveryProduct.VehicleNumber = requestedProduct.VehicleNumber
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ func (s salesOrdersService) getOne(c *fiber.Ctx, id uint) (*entity.Marketing, er
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "SalesOrders not found")
|
||||
}
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed get marketing by id: %+v", err)
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch sales order")
|
||||
}
|
||||
|
||||
@@ -293,13 +292,17 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
|
||||
for _, rp := range req.MarketingProducts {
|
||||
if old, ok := oldByPW[rp.ProductWarehouseId]; ok {
|
||||
|
||||
// Hitung total_weight dan total_price otomatis
|
||||
totalWeight := rp.Qty * rp.AvgWeight
|
||||
totalPrice := rp.UnitPrice * rp.Qty
|
||||
|
||||
updateBody := map[string]any{
|
||||
"product_warehouse_id": rp.ProductWarehouseId,
|
||||
"qty": rp.Qty,
|
||||
"unit_price": rp.UnitPrice,
|
||||
"avg_weight": rp.AvgWeight,
|
||||
"total_weight": rp.TotalWeight,
|
||||
"total_price": rp.TotalPrice,
|
||||
"total_weight": totalWeight,
|
||||
"total_price": totalPrice,
|
||||
}
|
||||
if err := marketingProductRepoTx.PatchOne(c.Context(), old.Id, updateBody, nil); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update marketing product")
|
||||
@@ -589,30 +592,34 @@ func (s salesOrdersService) Approval(c *fiber.Ctx, req *validation.Approve) ([]e
|
||||
|
||||
func (s *salesOrdersService) createMarketingProductWithDelivery(ctx context.Context, marketingId uint, rp validation.CreateMarketingProduct, marketingProductRepo repository.MarketingProductRepository, invDeliveryRepo repository.MarketingDeliveryProductRepository) error {
|
||||
|
||||
// Hitung total_weight dan total_price otomatis
|
||||
totalWeight := rp.Qty * rp.AvgWeight
|
||||
totalPrice := rp.UnitPrice * rp.Qty
|
||||
|
||||
marketingProduct := &entity.MarketingProduct{
|
||||
MarketingId: marketingId,
|
||||
ProductWarehouseId: rp.ProductWarehouseId,
|
||||
Qty: rp.Qty,
|
||||
UnitPrice: rp.UnitPrice,
|
||||
AvgWeight: rp.AvgWeight,
|
||||
TotalWeight: rp.TotalWeight,
|
||||
TotalPrice: rp.TotalPrice,
|
||||
TotalWeight: totalWeight,
|
||||
TotalPrice: totalPrice,
|
||||
}
|
||||
if err := marketingProductRepo.CreateOne(ctx, marketingProduct, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
marketingDeliveryProduct := &entity.MarketingDeliveryProduct{
|
||||
MarketingProductId: marketingProduct.Id,
|
||||
ProductWarehouseId: marketingProduct.ProductWarehouseId,
|
||||
UnitPrice: 0,
|
||||
TotalWeight: 0,
|
||||
AvgWeight: 0,
|
||||
TotalPrice: 0,
|
||||
DeliveryDate: nil,
|
||||
VehicleNumber: rp.VehicleNumber,
|
||||
UsageQty: 0,
|
||||
PendingQty: 0,
|
||||
MarketingProductId: marketingProduct.Id,
|
||||
ProductWarehouseId: marketingProduct.ProductWarehouseId,
|
||||
UnitPrice: 0,
|
||||
TotalWeight: 0,
|
||||
AvgWeight: 0,
|
||||
TotalPrice: 0,
|
||||
DeliveryDate: nil,
|
||||
VehicleNumber: rp.VehicleNumber,
|
||||
UsageQty: 0,
|
||||
PendingQty: 0,
|
||||
}
|
||||
if err := invDeliveryRepo.CreateOne(ctx, marketingDeliveryProduct, nil); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user