Fix item counts, PR/QT conversions, validation and department loss
This commit is contained in:
@@ -15,10 +15,6 @@ if (!$request_id) {
|
||||
$answer['message'] = 'Purchase request ID is required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
if (!$contact_id) {
|
||||
$answer['message'] = 'Supplier (contact_id) is required for the PO.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$prm = new PurchaseRequestManager($pdo2, $company_id);
|
||||
|
||||
@@ -29,6 +25,15 @@ if (!$pr || (int)$pr['status'] !== 2) {
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
// Default to the PR's preferred supplier
|
||||
if (!$contact_id) {
|
||||
$contact_id = (int)($pr['contact_id'] ?? 0);
|
||||
}
|
||||
if (!$contact_id) {
|
||||
$answer['message'] = 'Set a Preferred Supplier on this purchase request before converting it to a PO.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$pr_items = $pr['items'];
|
||||
if (empty($pr_items)) {
|
||||
$answer['message'] = 'Purchase request has no items.';
|
||||
@@ -92,6 +97,7 @@ foreach ($convert_items as $ci) {
|
||||
'unit_price' => $unit_price,
|
||||
'total_price' => $total_price,
|
||||
'tax_amount' => $tax_amount,
|
||||
'tax_rate' => (float)($pi['tax_rate'] ?? 0),
|
||||
'received_qty' => 0,
|
||||
'stock_in_id' => 0,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user