CHANGE_ in sales module product : GWM
This commit is contained in:
parent
6be1d1b703
commit
d292487c10
@ -153,11 +153,12 @@ class Sales extends BaseController
|
||||
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||
$SalesOrderModel = new SalesOrderModel();
|
||||
$ProductModel = new ProductModel();
|
||||
$SalesOrderProductModel = new SalesOrderProductModel(); // Assuming you have a model for sales_order_product
|
||||
$SalesOrderProductModel = new SalesOrderProductModel();
|
||||
|
||||
|
||||
|
||||
// Prepare data for sales order
|
||||
$status = $this->request->getPost('status') != '' ? $this->request->getPost('status') : 'Draft';
|
||||
$data = [
|
||||
'client_name' => $this->request->getPost('client_id'),
|
||||
'vehicle_id'=>$this->request->getPost('vehicle_id'),
|
||||
@ -166,35 +167,38 @@ class Sales extends BaseController
|
||||
'mobile_no' => $this->request->getPost('mobile_no'),
|
||||
'billing_state' => $this->request->getPost('state'),
|
||||
'billing_postal_code' => $this->request->getPost('postalcode'),
|
||||
// 'billing_country' => $this->request->getPost('country'),
|
||||
'terms_condition' => $this->request->getPost('terms_condition'),
|
||||
'subtotal' => $this->request->getPost('sub_total'),
|
||||
'tax' => $this->request->getPost('invoice_tax'),
|
||||
|
||||
'total'=> $this->request->getPost('grand_total'),
|
||||
'status'=> $this->request->getPost('status'),
|
||||
'isactive' => 1, // Assuming this is a default value or handled separately
|
||||
'status'=> $status,
|
||||
'isactive' => 1,
|
||||
'branch_id'=> $this->session->get('logged_user_branch_id'),
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Insert or update sales order
|
||||
$sales_order_id = $this->request->getPost('sales_order_id');
|
||||
|
||||
if (!empty($sales_order_id)) {
|
||||
if ($this->request->getPost('status') === "Paid") {
|
||||
|
||||
//update sales-order
|
||||
if ($status === "Approved") {
|
||||
$data['mode_of_payment'] = $this->request->getPost('mode_of_payment');
|
||||
}
|
||||
$SalesOrderModel->update($sales_order_id, $data);
|
||||
} else {
|
||||
$data['inv_no'] = InvNoHelper::generateInvoiceNumber();
|
||||
|
||||
// dd($data);
|
||||
} else {
|
||||
|
||||
//create sales-order
|
||||
$data['inv_no'] = InvNoHelper::generateInvoiceNumber();
|
||||
$SalesOrderModel->insert($data);
|
||||
$sales_order_id = $SalesOrderModel->getInsertID();
|
||||
|
||||
// Update sales order with generated order number
|
||||
$orderNumber = 'SO-' . date('md') . '-' . str_pad($sales_order_id, 5, '0', STR_PAD_LEFT);
|
||||
$SalesOrderModel->update($sales_order_id, ['order_number' => $orderNumber]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -211,22 +215,16 @@ class Sales extends BaseController
|
||||
$product_names_id = $this->request->getPost('product_names_id');
|
||||
|
||||
|
||||
$status = $this->request->getPost('status');
|
||||
foreach ($product_ids as $key => $product_id) {
|
||||
|
||||
foreach ($product_ids as $key => $product_id)
|
||||
{
|
||||
|
||||
|
||||
// $product_id = null;
|
||||
// $product_names_id = null;
|
||||
|
||||
// list($product_id, $product_names_id) = explode('-', $product_string);
|
||||
|
||||
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
|
||||
if ($status == 'Created') {
|
||||
if ($status == 'Approved') {
|
||||
$this->subractProductQuantity($ProductModel, $product_id, $qty);
|
||||
}elseif ($status == 'Cancelled'){
|
||||
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
|
||||
}
|
||||
|
||||
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
|
||||
$discount_type = isset($discount_types[$key]) ? $discount_types[$key] : '';
|
||||
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
|
||||
@ -350,7 +348,7 @@ class Sales extends BaseController
|
||||
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||
// Fetch the invoice data based on $invoice_id
|
||||
$model = new SalesOrderModel();
|
||||
$saleOrderCount = count($model->where('status','Paid')->findAll());
|
||||
$saleOrderCount = count($model->where('status','Approved')->findAll());
|
||||
$VehicleModel = new VehicleModel();
|
||||
$BranchModel = new BranchModel();
|
||||
$BusinessModel = new BusinessModel();
|
||||
@ -386,29 +384,19 @@ class Sales extends BaseController
|
||||
|
||||
// Generate the PDF content (HTML)
|
||||
if ($data['sales'][0]->status === 'Draft') {
|
||||
// Set the watermark text and options
|
||||
$mpdf->SetWatermarkText('Draft');
|
||||
$mpdf->showWatermarkText = true;
|
||||
}
|
||||
if ($data['sales'][0]->status === 'Cancelled') {
|
||||
// Set the watermark text and options
|
||||
$mpdf->SetWatermarkText('Cancelled');
|
||||
$mpdf->showWatermarkText = true;
|
||||
}
|
||||
if ($data['sales'][0]->status === 'Void') {
|
||||
// Set the watermark text and options
|
||||
$mpdf->SetWatermarkText('Void');
|
||||
$mpdf->showWatermarkText = true;
|
||||
}
|
||||
|
||||
|
||||
// Generate the PDF content (HTML) with data
|
||||
$html = view('invoice_pdf_template', $data);
|
||||
// echo $html;die;
|
||||
// Load HTML into the mPDF instance
|
||||
$mpdf->WriteHTML($html);
|
||||
date_default_timezone_set('Asia/Kolkata');
|
||||
// Output the PDF to the browser for download
|
||||
$mpdf->Output($data['sales'][0]->order_number .'_' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
||||
}
|
||||
|
||||
@ -419,7 +407,7 @@ class Sales extends BaseController
|
||||
|
||||
// Fetch the invoice data based on $invoice_id
|
||||
$model = new SalesOrderModel();
|
||||
$saleOrderCount = count($model->where('status','Paid')->findAll());
|
||||
$saleOrderCount = count($model->where('status','Approved')->findAll());
|
||||
$VehicleModel = new VehicleModel();
|
||||
$BranchModel = new BranchModel();
|
||||
$BusinessModel = new BusinessModel();
|
||||
@ -539,7 +527,7 @@ class Sales extends BaseController
|
||||
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
|
||||
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
|
||||
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
|
||||
->where('qty_stock >',0)
|
||||
// ->where('qty_stock >',0)
|
||||
->where('products.isactive', 1)
|
||||
->findAll();
|
||||
|
||||
@ -551,7 +539,7 @@ class Sales extends BaseController
|
||||
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
|
||||
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
|
||||
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
|
||||
->where('qty_stock >',0)
|
||||
// ->where('qty_stock >',0)
|
||||
->where('products.isactive', 1)
|
||||
->findAll();
|
||||
|
||||
|
||||
@ -9,16 +9,16 @@
|
||||
float:left;
|
||||
}
|
||||
.cancelled-status {
|
||||
color: red;
|
||||
}
|
||||
color: red;
|
||||
}
|
||||
|
||||
.created-status {
|
||||
color: blue;
|
||||
}
|
||||
.Draft-status {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.paid-status {
|
||||
color: green;
|
||||
}
|
||||
.Approved-status {
|
||||
color: green;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
@ -75,23 +75,12 @@
|
||||
<td><?= $value['order_number']; ?></td>
|
||||
<td><?= $value['reg_no']; ?></td>
|
||||
<td><?= $value['client_name']; ?></td>
|
||||
|
||||
<td><?= $value['product_count']; ?></td>
|
||||
<td><?= $value['product_qty']; ?></td>
|
||||
|
||||
<td><?= $value['total']; ?></td>
|
||||
<td class="<?php
|
||||
if ($value['status'] == 'Cancelled') {
|
||||
echo 'cancelled-status';
|
||||
} elseif ($value['status'] == 'Created') {
|
||||
echo 'created-status';
|
||||
} elseif ($value['status'] == 'Paid') {
|
||||
echo 'paid-status';
|
||||
}
|
||||
?>">
|
||||
<td class="<?php if ($value['status'] == 'Cancelled') { echo 'cancelled-status'; } elseif ($value['status'] == 'Draft') { echo 'Draft-status'; } elseif ($value['status'] == 'Approved') { echo 'Approved-status';} ?>">
|
||||
<?= $value['status']; ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div class="btn-group dropdown">
|
||||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
||||
|
||||
@ -81,23 +81,22 @@
|
||||
<?php echo "( ". $sales['status']." )"; ?>
|
||||
<?php endif; ?></label>
|
||||
|
||||
<select class="form-control status-select status_class_for_change" name="status" data-toggle="select2" style="background-color: aquamarine;color: darkblue;">
|
||||
<select class="form-control status-select status_class_for_change" name="status" data-toggle="select2" >
|
||||
<?php if (isset($sales['status'])): ?>
|
||||
<?php if ($sales['status'] === 'Cancelled'): ?>
|
||||
|
||||
<option value="Created" <?= $sales['status'] === 'Created' ? 'selected' : '' ?>>Created </option>
|
||||
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<option value="Draft" <?= $sales['status'] === 'Draft' ? 'selected' : '' ?> >Draft </option>
|
||||
<option value="Approved" <?= $sales['status'] === 'Approved' ? 'selected' : '' ?>>Approved</option>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<option value>Select Status</option>
|
||||
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<option value="Approved" <?= $sales['status'] === 'Approved' ? 'selected' : '' ?>>Approved</option>
|
||||
<option value="Cancelled" <?= $sales['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<option value="Created" selected>Created</option>
|
||||
<!-- <option value="Paid">Paid</option> -->
|
||||
<option value="Draft" selected>Draft</option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
@ -105,7 +104,7 @@
|
||||
|
||||
<?php if (isset($sales['status']) && $sales['status'] !== ''): ?>
|
||||
|
||||
<div class="form-group col-md-4" id="mode_of_payment_parent_div_id" <?= $sales['status'] === 'Paid' ? '' : 'style="display:none;"' ?>>
|
||||
<div class="form-group col-md-4" id="mode_of_payment_parent_div_id" <?= $sales['status'] === 'Approved' ? '' : 'style="display:none;"' ?>>
|
||||
<label for="mode_of_payment" class="col-form-label">Mode Of Payment<span class="text-danger">*</span>
|
||||
<select class="form-control" name="mode_of_payment" id="mode_of_payment" >
|
||||
<option value>Select Mode Of Payment</option>
|
||||
@ -166,7 +165,7 @@
|
||||
<th>Item Details</th>
|
||||
<th>Rate</th>
|
||||
<th>Qty</th>
|
||||
<th>Taxable Amt</th>
|
||||
<th>Amt</th>
|
||||
<th>Tax</th>
|
||||
<th>Tax Amt</th>
|
||||
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
|
||||
@ -311,7 +310,7 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($sales['status']) || $sales['status'] !== 'Paid') : ?>
|
||||
<?php if (!isset($sales['status']) || $sales['status'] !== 'Approved') : ?>
|
||||
<button type="submit" id="editaddbutton" class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
|
||||
@ -1059,7 +1058,7 @@ $(document).on('click', '#selectClient', function() {
|
||||
|
||||
$('.status_class_for_change').change(function (params) {
|
||||
|
||||
if($(this).val() === 'Paid'){
|
||||
if($(this).val() === 'Approved'){
|
||||
$('#mode_of_payment_parent_div_id').css('display','');
|
||||
$('#mode_of_payment').prop('required','required');
|
||||
}else{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user