supplier do recalculate

This commit is contained in:
Edmond Teh
2020-09-26 18:49:28 +08:00
parent fdb52929cd
commit 6a67231aa2
+22 -5
View File
@@ -470,13 +470,30 @@ class InvoiceController extends Controller
$booking = Booking::where('id', $id)->first();
$invoice = Invoice::where('booking_id', $booking['id'])->first();
$lines = InvoiceDetails::where('invoice_id', $invoice->id)->get();
$supplierbooking = SupplierBooking::where('booking_id', $id)->first();
$lines = DB::table('invoices')
->join('invoice_details', function ($join) use ($id) {
$join->where('invoices.booking_id', '=', $id);
$join->on('invoice_details.invoice_id', '=', 'invoices.id');
})
->join('supplier_bookings', 'invoices.booking_id', '=', 'supplier_bookings.booking_id')
->select(
'order',
'stock_code',
'description',
'quantity',
DB::raw('ROUND((invoice_details.unit_price_rmb / supplier_bookings.rate), 2) as unit_price_rm'),
DB::raw('ROUND((invoice_details.quantity * ROUND((invoice_details.unit_price_rmb / supplier_bookings.rate), 2)), 2) as total'),
// subtotal
// adjustment
// total
)->get();
$supplierbooking = SupplierBooking::where('booking_id', $id)->first();
$supplier = SettingSupplier::where('id', $supplierbooking->supplier_id)->first();
$subtotal = InvoiceDetails::where('invoice_id', $invoice->id)->sum('total');
$adjustment = $invoice->adjustment;
$billing_charges = $booking->billing_charge;
$total = $subtotal + $adjustment + $billing_charges;
$subtotal = $lines->sum('total');
$billing_charges = null;
$total = $supplierbooking->amount_after_tax;
$adjustment = $total - $subtotal;
$data = [
'title' => 'Delivery Order',