Merge branch 'do_packing_list_auto_fill' into 'development'

auto generate product list

See merge request CIEFWorldwideSdnBhd/exchange-2.0!72
This commit is contained in:
Leong Chee Siong
2022-01-10 03:25:50 +00:00
4 changed files with 142 additions and 3 deletions
@@ -0,0 +1,116 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\ControllersLogic\CreatePurchaseOrderTransactionLogic;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use App\Models\Transaction;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AutoPackingListFillLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Purchase Order Approval',
'message' => 'You have successfully updated the Purchase order status'
];
}
/** @var CreatePurchaseOrderTransactionLogic */
private $createPurchaseOrderTransactionLogic;
/**
* AutoPackingListFillLogic constructor.
* @param CreatePurchaseOrderTransactionLogic $createPurchaseOrderTransactionLogic
*/
public function __construct(CreatePurchaseOrderTransactionLogic $createPurchaseOrderTransactionLogic)
{
$this->createPurchaseOrderTransactionLogic = $createPurchaseOrderTransactionLogic;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
$booking = Booking::where('created_at', '>', '01-07-2021')
->whereDoesntHave('transactions', function($q){
$q->where('type', TransactionType::PURCHASE_ORDER);
$q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]);
})
->get();
foreach ($booking as $key => $row) {
$amount = $row->fix_amount;
$other_transaction = Transaction::
where('type', TransactionType::PURCHASE_ORDER)
->where('status', ApprovalStatus::APPROVED)
->where('amount', '<=', $amount)
->where('issuer', $row->company_id)
->first();
if (!$other_transaction) {
$other_transaction = Transaction::
where('type', TransactionType::PURCHASE_ORDER)
->where('status', ApprovalStatus::APPROVED)
->where('amount', '<=', $amount)
->first();
}
if ($other_transaction) {
$other_transaction_detail = $other_transaction->transactionDetails()->get();
$other_amount = 0;
foreach ($other_transaction_detail as $key_2 => $row_2) {
if ($amount > $other_amount) {
$other_amount += $row_2->amount;
$products[] = [
'description' => $row_2->product_name,
'quantity' => (int) $row_2->quantity,
'stockCode' => $row_2->product_code,
'total' => $row_2->amount,
'unit_price' => (int) $row_2->price,
];
}
}
$remain_amount = $amount - $other_amount;
if ($remain_amount > 0) {
$remain = [
'description' => 'other service charge',
'quantity' => 1,
'stockCode' => 'OTHER_SERVICE_CHARGE',
'total' => $remain_amount,
'unit_price' => $remain_amount,
];
$products = array_merge([$remain], $products);
}
$request->request->add([
'products' => $products
]);
$create_transaction = $this->createPurchaseOrderTransactionLogic->logic($request, $row->id);
}
}
return $this->response([]);
}
}
@@ -83,16 +83,15 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
public function logic(Request $request, $id = '') : JsonResponse
{
/** @var Booking $booking */
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
$booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]);
/** @var Transaction $transaction */
$transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first();
$billNumber = $this->generatesTransactionBillNumber->execute('PO-');
$total = collect($request->input('products'))->sum(function($product){
return $product['quantity'] * floatval(str_replace(',', '', $product['unit_price']));
});
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\AutoPackingListFillLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AutoPackingListFillController
{
/**
* @param Request $request
* @param AutoPackingListFillLogic $logic
* @return JsonResponse
*/
public function auto(Request $request, AutoPackingListFillLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+4
View File
@@ -31,4 +31,8 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking
Route::post('/merge', 'MergeBookingController@merge')->name('merge');
Route::post('{id}/proforma/create', 'CreateProformaInvoiceTransaction@create')->name('proforma.create');
Route::post('/auto-packing-list-fill', 'AutoPackingListFillController@auto')->name('assign');
});