CHANGE_ in sales module product : GWM

This commit is contained in:
Smart 2024-10-18 16:46:15 +05:30
parent 6be1d1b703
commit d292487c10
3 changed files with 40 additions and 64 deletions

View File

@ -153,11 +153,12 @@ class Sales extends BaseController
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
$SalesOrderModel = new SalesOrderModel(); $SalesOrderModel = new SalesOrderModel();
$ProductModel = new ProductModel(); $ProductModel = new ProductModel();
$SalesOrderProductModel = new SalesOrderProductModel(); // Assuming you have a model for sales_order_product $SalesOrderProductModel = new SalesOrderProductModel();
// Prepare data for sales order // Prepare data for sales order
$status = $this->request->getPost('status') != '' ? $this->request->getPost('status') : 'Draft';
$data = [ $data = [
'client_name' => $this->request->getPost('client_id'), 'client_name' => $this->request->getPost('client_id'),
'vehicle_id'=>$this->request->getPost('vehicle_id'), 'vehicle_id'=>$this->request->getPost('vehicle_id'),
@ -166,35 +167,38 @@ class Sales extends BaseController
'mobile_no' => $this->request->getPost('mobile_no'), 'mobile_no' => $this->request->getPost('mobile_no'),
'billing_state' => $this->request->getPost('state'), 'billing_state' => $this->request->getPost('state'),
'billing_postal_code' => $this->request->getPost('postalcode'), 'billing_postal_code' => $this->request->getPost('postalcode'),
// 'billing_country' => $this->request->getPost('country'),
'terms_condition' => $this->request->getPost('terms_condition'), 'terms_condition' => $this->request->getPost('terms_condition'),
'subtotal' => $this->request->getPost('sub_total'), 'subtotal' => $this->request->getPost('sub_total'),
'tax' => $this->request->getPost('invoice_tax'), 'tax' => $this->request->getPost('invoice_tax'),
'total'=> $this->request->getPost('grand_total'), 'total'=> $this->request->getPost('grand_total'),
'status'=> $this->request->getPost('status'), 'status'=> $status,
'isactive' => 1, // Assuming this is a default value or handled separately 'isactive' => 1,
'branch_id'=> $this->session->get('logged_user_branch_id'), 'branch_id'=> $this->session->get('logged_user_branch_id'),
]; ];
// Insert or update sales order // Insert or update sales order
$sales_order_id = $this->request->getPost('sales_order_id'); $sales_order_id = $this->request->getPost('sales_order_id');
if (!empty($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'); $data['mode_of_payment'] = $this->request->getPost('mode_of_payment');
} }
$SalesOrderModel->update($sales_order_id, $data); $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); $SalesOrderModel->insert($data);
$sales_order_id = $SalesOrderModel->getInsertID(); $sales_order_id = $SalesOrderModel->getInsertID();
// Update sales order with generated order number // Update sales order with generated order number
$orderNumber = 'SO-' . date('md') . '-' . str_pad($sales_order_id, 5, '0', STR_PAD_LEFT); $orderNumber = 'SO-' . date('md') . '-' . str_pad($sales_order_id, 5, '0', STR_PAD_LEFT);
$SalesOrderModel->update($sales_order_id, ['order_number' => $orderNumber]); $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'); $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; $qty = isset($quantities[$key]) ? $quantities[$key] : 0;
if ($status == 'Created') { if ($status == 'Approved') {
$this->subractProductQuantity($ProductModel, $product_id, $qty); $this->subractProductQuantity($ProductModel, $product_id, $qty);
}elseif ($status == 'Cancelled'){ }elseif ($status == 'Cancelled'){
$this->addBackProductQuantity($ProductModel, $product_id, $qty); $this->addBackProductQuantity($ProductModel, $product_id, $qty);
} }
$discount = isset($discounts[$key]) ? $discounts[$key] : 0; $discount = isset($discounts[$key]) ? $discounts[$key] : 0;
$discount_type = isset($discount_types[$key]) ? $discount_types[$key] : ''; $discount_type = isset($discount_types[$key]) ? $discount_types[$key] : '';
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0; $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()); } if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
// Fetch the invoice data based on $invoice_id // Fetch the invoice data based on $invoice_id
$model = new SalesOrderModel(); $model = new SalesOrderModel();
$saleOrderCount = count($model->where('status','Paid')->findAll()); $saleOrderCount = count($model->where('status','Approved')->findAll());
$VehicleModel = new VehicleModel(); $VehicleModel = new VehicleModel();
$BranchModel = new BranchModel(); $BranchModel = new BranchModel();
$BusinessModel = new BusinessModel(); $BusinessModel = new BusinessModel();
@ -386,29 +384,19 @@ class Sales extends BaseController
// Generate the PDF content (HTML) // Generate the PDF content (HTML)
if ($data['sales'][0]->status === 'Draft') { if ($data['sales'][0]->status === 'Draft') {
// Set the watermark text and options
$mpdf->SetWatermarkText('Draft'); $mpdf->SetWatermarkText('Draft');
$mpdf->showWatermarkText = true; $mpdf->showWatermarkText = true;
} }
if ($data['sales'][0]->status === 'Cancelled') { if ($data['sales'][0]->status === 'Cancelled') {
// Set the watermark text and options
$mpdf->SetWatermarkText('Cancelled'); $mpdf->SetWatermarkText('Cancelled');
$mpdf->showWatermarkText = true; $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 // Generate the PDF content (HTML) with data
$html = view('invoice_pdf_template', $data); $html = view('invoice_pdf_template', $data);
// echo $html;die;
// Load HTML into the mPDF instance
$mpdf->WriteHTML($html); $mpdf->WriteHTML($html);
date_default_timezone_set('Asia/Kolkata'); 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'); $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 // Fetch the invoice data based on $invoice_id
$model = new SalesOrderModel(); $model = new SalesOrderModel();
$saleOrderCount = count($model->where('status','Paid')->findAll()); $saleOrderCount = count($model->where('status','Approved')->findAll());
$VehicleModel = new VehicleModel(); $VehicleModel = new VehicleModel();
$BranchModel = new BranchModel(); $BranchModel = new BranchModel();
$BusinessModel = new BusinessModel(); $BusinessModel = new BusinessModel();
@ -539,7 +527,7 @@ class Sales extends BaseController
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false) ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->where('qty_stock >',0) // ->where('qty_stock >',0)
->where('products.isactive', 1) ->where('products.isactive', 1)
->findAll(); ->findAll();
@ -551,7 +539,7 @@ class Sales extends BaseController
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false) ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->where('qty_stock >',0) // ->where('qty_stock >',0)
->where('products.isactive', 1) ->where('products.isactive', 1)
->findAll(); ->findAll();

View File

@ -12,11 +12,11 @@
color: red; color: red;
} }
.created-status { .Draft-status {
color: blue; color: blue;
} }
.paid-status { .Approved-status {
color: green; color: green;
} }
@ -75,23 +75,12 @@
<td><?= $value['order_number']; ?></td> <td><?= $value['order_number']; ?></td>
<td><?= $value['reg_no']; ?></td> <td><?= $value['reg_no']; ?></td>
<td><?= $value['client_name']; ?></td> <td><?= $value['client_name']; ?></td>
<td><?= $value['product_count']; ?></td> <td><?= $value['product_count']; ?></td>
<td><?= $value['product_qty']; ?></td> <td><?= $value['product_qty']; ?></td>
<td><?= $value['total']; ?></td> <td><?= $value['total']; ?></td>
<td class="<?php <td class="<?php if ($value['status'] == 'Cancelled') { echo 'cancelled-status'; } elseif ($value['status'] == 'Draft') { echo 'Draft-status'; } elseif ($value['status'] == 'Approved') { echo 'Approved-status';} ?>">
if ($value['status'] == 'Cancelled') {
echo 'cancelled-status';
} elseif ($value['status'] == 'Created') {
echo 'created-status';
} elseif ($value['status'] == 'Paid') {
echo 'paid-status';
}
?>">
<?= $value['status']; ?> <?= $value['status']; ?>
</td> </td>
<td> <td>
<div class="btn-group dropdown"> <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> <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>

View File

@ -81,23 +81,22 @@
<?php echo "( ". $sales['status']." )"; ?> <?php echo "( ". $sales['status']." )"; ?>
<?php endif; ?></label> <?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 (isset($sales['status'])): ?>
<?php if ($sales['status'] === 'Cancelled'): ?> <?php if ($sales['status'] === 'Cancelled'): ?>
<option value="Created" <?= $sales['status'] === 'Created' ? 'selected' : '' ?>>Created </option> <option value="Draft" <?= $sales['status'] === 'Draft' ? 'selected' : '' ?> >Draft </option>
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option> <option value="Approved" <?= $sales['status'] === 'Approved' ? 'selected' : '' ?>>Approved</option>
<?php else: ?> <?php else: ?>
<option value>Select Status</option> <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> <option value="Cancelled" <?= $sales['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
<?php endif; ?> <?php endif; ?>
<?php else: ?> <?php else: ?>
<option value="Created" selected>Created</option> <option value="Draft" selected>Draft</option>
<!-- <option value="Paid">Paid</option> -->
<?php endif; ?> <?php endif; ?>
</select> </select>
@ -105,7 +104,7 @@
<?php if (isset($sales['status']) && $sales['status'] !== ''): ?> <?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> <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" > <select class="form-control" name="mode_of_payment" id="mode_of_payment" >
<option value>Select Mode Of Payment</option> <option value>Select Mode Of Payment</option>
@ -166,7 +165,7 @@
<th>Item Details</th> <th>Item Details</th>
<th>Rate</th> <th>Rate</th>
<th>Qty</th> <th>Qty</th>
<th>Taxable Amt</th> <th>Amt</th>
<th>Tax</th> <th>Tax</th>
<th>Tax Amt</th> <th>Tax Amt</th>
<!-- <th style="text-align: center !important" colspan="2">Discount</th> --> <!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
@ -311,7 +310,7 @@
</div> </div>
</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> <button type="submit" id="editaddbutton" class="btn btn-primary">Submit</button>
<?php endif; ?> <?php endif; ?>
@ -1059,7 +1058,7 @@ $(document).on('click', '#selectClient', function() {
$('.status_class_for_change').change(function (params) { $('.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_parent_div_id').css('display','');
$('#mode_of_payment').prop('required','required'); $('#mode_of_payment').prop('required','required');
}else{ }else{