diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 1614604..652bc70 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -2,6 +2,7 @@ namespace App\Controllers; use App\Models\BusinessModel; +use App\Models\BranchModel; use App\Models\JobcardModel; use App\Models\JobcardComplaintModel; use App\Models\JobcardCustomComplaintModel; @@ -27,6 +28,7 @@ class Jobcard extends BaseController public $BikemakeModel; public $BusinessModel; public $JobcardModel; + public $BranchModel; public function __construct() { @@ -35,6 +37,7 @@ class Jobcard extends BaseController $this->BikemakeModel = new BikemakeModel(); $this->BusinessModel = new BusinessModel(); $this->JobcardModel = new JobcardModel(); + $this->BranchModel = new BranchModel(); } @@ -56,9 +59,20 @@ class Jobcard extends BaseController $data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id); $bus_id = $this->session->get('logged_user_business_id'); $data['job_card'] = $this->JobcardModel->where('job_card_id',$job_card_id)->findAll(); - $data['company_address'] = $this->BusinessModel->where('business_id', $bus_id)->where('isactive', 1)->findAll(); + $data['company_address'] = $this->BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->where('business_id', $bus_id)->where('isactive', 1)->findAll(); + // echo json_encode($data['company_address']);die; $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); // echo json_encode($productdata);die; + + if($data['job_card'][0]['inv_no'] == '') + { + /** GENERATE INV NO */ + $uniqueId = sprintf('%06d', mt_rand(0, 999999)); + $date = date('Ymdhms'); + $invoiceNumber = 'INV' . '-' . $date . $uniqueId; + $this->JobcardModel->update($job_card_id,['inv_no' => $invoiceNumber]); + $data['job_card'][0]['inv_no'] = $invoiceNumber; + } $servicedata = $this->JobcardModel->get_jobcard_service($job_card_id); $complaintdata = $this->JobcardModel->get_jobcard_complaint($job_card_id); @@ -70,7 +84,7 @@ class Jobcard extends BaseController // Calculate total amount and total tax foreach ($labourcost as $product) { $totalAmount += $product["labour_amount"]; - $totalTax += $product["labour_amount"] * ($product["tax"] / 100); + $totalTax = $product["tax"]; } // Calculate total @@ -115,7 +129,7 @@ class Jobcard extends BaseController // Generate the PDF content (HTML) with data $html = view('invoice_pdf_template_jobcard', $data); - +echo $html;die; // Load HTML into the mPDF instance $mpdf->WriteHTML($html); @@ -305,6 +319,7 @@ class Jobcard extends BaseController 'store_item_issued'=> $this->request->getPost('store_item_issued'), 'subtotal'=> $this->request->getPost('sub_total'), 'tax'=> $this->request->getPost('invoicetax'), + 'discount'=> ($this->request->getPost('discount')) == '' ? 0 : $this->request->getPost('discount'), 'total'=> $this->request->getPost('grand_total'), 'isactive' => 1 ]; @@ -425,16 +440,28 @@ class Jobcard extends BaseController public function delete_items($delArr) { + $JobcardProductModel = new JobcardProductModel(); $JobcardServiceModel = new JobcardServiceModel(); $JobcardComplaintModel = new JobcardComplaintModel(); $JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); $data = json_decode($delArr); + $product_data = $data[0]->product; + if(!empty($product_data)) { + foreach ($product_data as $item) { + $conditions = [ 'job_card_product_id' => $item ]; + // $product_deleted_data = $JobcardProductModel->where($conditions)->findAll(); + // $this->product_delete($service_deleted_data[0]['product_id']); + $JobcardProductModel->where($conditions)->delete(); + } + } + $service_data = $data[0]->service; if(!empty($service_data)) { foreach ($service_data as $item) { $conditions = [ 'job_card_service_id' => $item ]; $service_deleted_data = $JobcardServiceModel->where($conditions)->findAll(); + if(isset($service_deleted_data[0]['product_id'])) $this->product_delete($service_deleted_data[0]['product_id']); $JobcardServiceModel->where($conditions)->delete(); } @@ -445,6 +472,7 @@ class Jobcard extends BaseController foreach ($complaint_data as $item) { $conditions = [ 'job_card_complaint_id' => $item ]; $complaint_deleted_data = $JobcardComplaintModel->where($conditions)->findAll(); + if(isset($complaint_deleted_data[0]['product_id'])) $this->product_delete($complaint_deleted_data[0]['product_id']); $JobcardComplaintModel->where($conditions)->delete(); } @@ -455,6 +483,7 @@ class Jobcard extends BaseController foreach ($ccomplaint_data as $item) { $conditions = [ 'job_card_cc_id' => $item ]; $cc_deleted_data = $JobcardCustomComplaintModel->where($conditions)->findAll(); + if(isset($cc_deleted_data[0]['product_id'])) $this->product_delete($cc_deleted_data[0]['product_id']); $JobcardCustomComplaintModel->where($conditions)->delete(); } diff --git a/app/Models/JobcardModel.php b/app/Models/JobcardModel.php index aff855a..ebc91b0 100644 --- a/app/Models/JobcardModel.php +++ b/app/Models/JobcardModel.php @@ -5,10 +5,10 @@ class JobcardModel extends Model { protected $table = 'job_card'; protected $primaryKey = 'job_card_id'; - protected $allowedFields = ['job_card_id','vehicle_id','branch_id', + protected $allowedFields = ['job_card_id','inv_no','vehicle_id','branch_id', 'order_number','client_mobile_no','client_name', 'billing_address','billing_city','billing_state','billing_country', - 'billing_postal_code','status','assigned_to', 'store_item_issued','subtotal','tax','total','isactive']; + 'billing_postal_code','status','assigned_to', 'store_item_issued','subtotal','tax', 'discount','total','isactive']; @@ -80,7 +80,7 @@ class JobcardModel extends Model public function get_jobcard_service($job_id) { - $this->select('job_card.*, job_card_service.*, services.service_name as product_name, services.labour_cost as labour_amount'); + $this->select('job_card.*, job_card_service.*, services.service_name as product_name, job_card_service.labour_cost as labour_amount'); $this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id'); $this->join('services', 'services.service_id = job_card_service.service_id'); $this->where('job_card.isactive', 1); @@ -90,7 +90,7 @@ class JobcardModel extends Model public function get_jobcard_complaint($job_id) { - $this->select('job_card.*, job_card_complaint.*, complaints.name as product_name, complaints.labour_charge as labour_amount'); + $this->select('job_card.*, job_card_complaint.*, complaints.name as product_name, job_card_complaint.labour_cost as labour_amount'); $this->join('job_card_complaint', 'job_card_complaint.job_card_id = job_card.job_card_id'); $this->join('complaints', 'complaints.complaint_id = job_card_complaint.complaint_id'); $this->where('job_card.isactive', 1); diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 6506b58..1bc72f6 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -20,8 +20,8 @@ table.invoice-related-table {width: 100%;border-collapse: collapse;} table.invoice-related-table th,table.invoice-related-table td {border: none;padding: 8px;text-align: left;} table.invoice-related-table th {background-color: #DAC2AD;font-weight: bold;} - table.invoice-related-table thead tr th{border: 0.5px solid black;"} - table.invoice-related-table thead tr{border: 0.5px solid black;"} + table.invoice-related-table thead tr th{border: 0.5px solid black;} + table.invoice-related-table thead tr{border: 0.5px solid black;} .business-stamp, .terms {text-align: center;margin-top: 20px;} .subtotal-table {width: 100%;margin-top: 20px;} .subtotal-table table {width: 100%;border-collapse: collapse;border: 1px solid black;} diff --git a/app/Views/invoice_pdf_template_jobcard.php b/app/Views/invoice_pdf_template_jobcard.php index 1dc36bb..ba84884 100644 --- a/app/Views/invoice_pdf_template_jobcard.php +++ b/app/Views/invoice_pdf_template_jobcard.php @@ -154,7 +154,7 @@ p {
THE MECHANIC
= $value['address'] ?>,
= 'GSTNO: '.$value['gstno'] ?>
- = 'State Name: '.$value['state'].', code'.$value['code'] ?>
+ = 'State Name: '.$value['state'].', code'.$value['state_code'] ?>
= 'Contact: '.$value['postal_code'] ?>
= 'Email: '.$value['email'] ?>