Purchase-sale-Product-vendor
This commit is contained in:
parent
a7bfff8865
commit
e9845117d0
32
Mechanics.txt
Normal file
32
Mechanics.txt
Normal file
@ -0,0 +1,32 @@
|
||||
Mechanics
|
||||
|
||||
Sales order
|
||||
1.vehicle id readonly issue
|
||||
2.add more item in edit
|
||||
3.default qty should be 1 .amount should be qty*rate+tax (calculation changes)
|
||||
4.Sales order list client mobile tax subtotal should remove
|
||||
status cancel in red,create in blue and paid in green
|
||||
5.status label bracket hide in creat
|
||||
6.In edit make and model not show
|
||||
|
||||
Product
|
||||
1.model handle(reload existing selcted id should not remove)
|
||||
|
||||
|
||||
vehicle
|
||||
1.adding new client mobille number not populate
|
||||
|
||||
|
||||
Purchase order
|
||||
1.to set vendor read only
|
||||
2.add more item in edit
|
||||
3.STYLE IN ITEM SELCT
|
||||
4.Search in selct vendor column
|
||||
5.calculation should be removed only qty product name
|
||||
6.qty add in product when status is release is based on checkbox slected .only update will done if checked
|
||||
7.Pdf same as sales order
|
||||
|
||||
Return Products
|
||||
1.Same as purchase model .user can selct the product to be returned
|
||||
2.initially status is in draft nothing happens
|
||||
3.when status is returned qty should be decrease
|
||||
@ -125,5 +125,13 @@ $routes->post("add_purchase", "Purchase::add_purchase");
|
||||
$routes->get("delete_purchase/(:any)", "Purchase::delete_purchase/$1");
|
||||
$routes->post("getVendorProducts", "Purchase::getVendorProducts");
|
||||
$routes->post("delete_purchase_product", "Purchase::delete_purchase_product");
|
||||
$routes->get("download_purchase_invoice/(:any)", "Purchase::download_purchase_invoice/$1");
|
||||
// Reorder Level//
|
||||
$routes->get('reorder_level_index', 'Reorderlevel::reorder_level_index');
|
||||
$routes->get('rise_order/(:any)', 'Reorderlevel::rise_order/$1');
|
||||
// Return Order//
|
||||
$routes->get('return_order_index', 'ReturnOrder::return_order_index');
|
||||
$routes->get('return_order', 'ReturnOrder::return_order');
|
||||
$routes->get("new_return/(:any)", "ReturnOrder::new_return/$1");
|
||||
$routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1');
|
||||
$routes->post("add_purchase", "Purchase::add_purchase");
|
||||
|
||||
@ -8,6 +8,7 @@ use App\Models\PurchaseOrderModel;
|
||||
use App\Models\BranchModel;
|
||||
use App\Models\BusinessModel;
|
||||
use App\Models\PurchaseOrderChildModel;
|
||||
use Mpdf\Mpdf;
|
||||
|
||||
|
||||
class Purchase extends BaseController
|
||||
@ -40,7 +41,7 @@ class Purchase extends BaseController
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
|
||||
$vendor = $VendorModel->findAll();
|
||||
|
||||
|
||||
$BranchModel = new BranchModel();
|
||||
@ -69,7 +70,7 @@ class Purchase extends BaseController
|
||||
|
||||
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
|
||||
$vendor = $VendorModel->findAll();
|
||||
$data['vendor'] = $vendor;
|
||||
|
||||
$data['vendor_id'] = $purchase['vendor_id'];
|
||||
@ -115,16 +116,13 @@ class Purchase extends BaseController
|
||||
'shipping_state' => $this->request->getPost('shipping_state'),
|
||||
'shipping_city' =>$this->request->getPost('shipping_city'),
|
||||
'shipping_postal_code' => $this->request->getPost('shipping_postal_code'),
|
||||
|
||||
'bill_number' => $this->request->getPost('bill_number')? $this->request->getPost('bill_number') : '',
|
||||
'return_date' => $this->request->getPost('return_date') ? $this->request->getPost('return_date') : '',
|
||||
'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'),
|
||||
'branch_id'=> $this->session->get('logged_user_branch_id'),
|
||||
];
|
||||
|
||||
// print_r($data);
|
||||
// print_r($data);die;
|
||||
$purchase_order_id = $this->request->getPost('purchase_order_id');
|
||||
// echo $purchase_order_id;die;
|
||||
if (!empty($purchase_order_id)) {
|
||||
@ -148,22 +146,26 @@ class Purchase extends BaseController
|
||||
$amounts = $this->request->getPost('amount');
|
||||
$itemtax=$this->request->getPost('item-tax');
|
||||
$unitprice=$this->request->getPost('unit-price');
|
||||
$selected_items=$this->request->getPost('selected_items');
|
||||
$purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
|
||||
// print_r($purchase_order_child_id);die;
|
||||
// print_r($selected_items);die;
|
||||
|
||||
// print_r($status);die;
|
||||
$status = $this->request->getPost('purchase_status');
|
||||
foreach ($product_ids as $key => $product_id) {
|
||||
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
|
||||
if ($status == 'Released')
|
||||
// echo "hello";die;
|
||||
$selected_item= isset($selected_items[$key]) ? $selected_items[$key] : 0;
|
||||
// print_r($selected_item);die;
|
||||
if ($status == 'Received' && $selected_item == 1) {
|
||||
$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;
|
||||
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
|
||||
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
|
||||
|
||||
// $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
|
||||
// print_r($discount_type);die;
|
||||
$child_data = [
|
||||
@ -175,9 +177,10 @@ class Purchase extends BaseController
|
||||
'net_price'=>$rate,
|
||||
'tax'=>$tax,
|
||||
'amount' => $amount,
|
||||
'is_selected'=>$selected_item,
|
||||
'isactive'=>1,
|
||||
];
|
||||
// print_r($child_data);die;
|
||||
// print_r($child_data);die;
|
||||
if (!empty($purchase_order_child_id[$key])) {
|
||||
|
||||
// print_r($purchase_order_child_id[$key]);die;
|
||||
@ -196,6 +199,7 @@ class Purchase extends BaseController
|
||||
}
|
||||
private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
|
||||
{
|
||||
|
||||
// Fetch current product quantity
|
||||
$product = $ProductModel->find($product_id);
|
||||
$current_qty = $product['qty_stock'];
|
||||
@ -283,5 +287,71 @@ public function delete_purchase_product()
|
||||
// Return error response if deletion fails
|
||||
return $this->response->setJSON(['success' => false]);
|
||||
}
|
||||
public function download_purchase_invoice($purchase_order_id)
|
||||
{
|
||||
// echo "hello"; die;
|
||||
// Fetch the invoice data based on $invoice_id
|
||||
$model = new PurchaseOrderModel();
|
||||
$data = $model->getPurchasePdf($purchase_order_id);
|
||||
|
||||
$items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||
|
||||
|
||||
|
||||
// print_r($items);die();
|
||||
|
||||
// print_r($invoiceItems);die();
|
||||
|
||||
// Create an mPDF object
|
||||
$mpdf = new Mpdf([
|
||||
'mode' => '',
|
||||
'format' => 'A5',
|
||||
'default_font_size' => 0,
|
||||
'default_font' => '',
|
||||
|
||||
// 'margin_right' => 1,
|
||||
'margin_top' => 6,
|
||||
'margin_bottom' => 6,
|
||||
'margin_header' => 6,
|
||||
'margin_footer' =>-30,
|
||||
'orientation' => 'P',
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
|
||||
// Set PDF properties
|
||||
$mpdf->SetTitle('Invoice');
|
||||
$mpdf->SetAuthor($data[0]->branch_name);
|
||||
$mpdf->SetCreator('');
|
||||
|
||||
|
||||
|
||||
// Generate the PDF content (HTML)
|
||||
// if ($data[0]->status === 'Draft') {
|
||||
// // Set the watermark text and options
|
||||
// $mpdf->SetWatermarkText('Draft');
|
||||
// $mpdf->showWatermarkText = true;
|
||||
// }
|
||||
// if ($data[0]->status === 'Cancelled') {
|
||||
// // Set the watermark text and options
|
||||
// $mpdf->SetWatermarkText('Cancelled');
|
||||
// $mpdf->showWatermarkText = true;
|
||||
// }
|
||||
// if ($data[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_purchase_template', ['sales' => $data,'items'=>$items]);
|
||||
// echo $html;die;
|
||||
// Load HTML into the mPDF instance
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Output the PDF to the browser for download
|
||||
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\VendorModel;
|
||||
|
||||
|
||||
class Reorderlevel extends BaseController
|
||||
@ -28,5 +29,15 @@ class Reorderlevel extends BaseController
|
||||
|
||||
return view('reorder_level_list',$data);
|
||||
}
|
||||
public function rise_order($product_id)
|
||||
{
|
||||
$ProductModel = new ProductModel();
|
||||
$products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
|
||||
$data['products']=$products;
|
||||
$vendorid= $products['prefered_vendor'];
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor=$VendorModel->where('vendor_id',$vendorid)->findAll();
|
||||
print_r($vendor);die;
|
||||
}
|
||||
}
|
||||
?>
|
||||
375
app/Controllers/ReturnOrder.php
Normal file
375
app/Controllers/ReturnOrder.php
Normal file
@ -0,0 +1,375 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\PurchaseOrderModel;
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\VendorModel;
|
||||
use App\Models\BranchModel;
|
||||
use App\Models\BusinessModel;
|
||||
use App\Models\PurchaseOrderChildModel;
|
||||
use App\Models\ReturnModel;
|
||||
use Mpdf\Mpdf;
|
||||
|
||||
|
||||
class ReturnOrder extends BaseController
|
||||
{
|
||||
public $session;
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = session();
|
||||
}
|
||||
|
||||
public function return_order_index()
|
||||
{
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
|
||||
$purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id'));
|
||||
// echo "<pre>";
|
||||
// print_r($product);die;
|
||||
$data['purchase']=$purchase;
|
||||
|
||||
$ReturnModel = new ReturnModel();
|
||||
|
||||
$return = $ReturnModel->findAll();
|
||||
$data['return']=$return;
|
||||
// echo "<pre>";
|
||||
// print_r($data);die;
|
||||
return view('return_order_liist',$data);
|
||||
}
|
||||
|
||||
public function return_order()
|
||||
{
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
|
||||
$purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id'));
|
||||
// echo "<pre>";
|
||||
// print_r($product);die;
|
||||
$data['purchase']=$purchase;
|
||||
|
||||
// echo "<pre>";
|
||||
// print_r($data);die;
|
||||
return view('return_list',$data);
|
||||
}
|
||||
public function new_return($purchase_order_id)
|
||||
{
|
||||
if ($purchase_order_id === '0') {
|
||||
|
||||
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
$data['purchase'] =$PurchaseOrderModel->getdata($this->session->get('logged_user_branch_id'));
|
||||
// print_r($data);die;
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor = $VendorModel->findAll();
|
||||
|
||||
|
||||
$BranchModel = new BranchModel();
|
||||
$BusinessModel = new BusinessModel();
|
||||
$branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
|
||||
$business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
|
||||
$ProductModel = new ProductModel();
|
||||
$product=$ProductModel
|
||||
->where('isactive',1)
|
||||
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
|
||||
$data['product']=$product;
|
||||
$data['branch'] = $branch;
|
||||
$data['business'] = $business;
|
||||
|
||||
$data['page_name']="Add Purchase Order";
|
||||
$data['vendor']=$vendor;
|
||||
|
||||
$data['vendor_id'] = [];
|
||||
} else if ($purchase_order_id !== '0') {
|
||||
$data['page_name']="Edit Purchase Order";
|
||||
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
$purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
|
||||
$data['purchase'] = $purchase;
|
||||
|
||||
|
||||
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor = $VendorModel->findAll();
|
||||
$data['vendor'] = $vendor;
|
||||
|
||||
$data['vendor_id'] = $purchase['vendor_id'];
|
||||
// print_r($vendor);die;
|
||||
$vendorId=$purchase['vendor_id'];
|
||||
$encodedVendorId = json_encode([$vendorId]);
|
||||
$productModel = new ProductModel();
|
||||
|
||||
// Query the database to find the product based on make_id and model_id
|
||||
$product = $productModel->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
|
||||
->findAll();
|
||||
$data['product']=$product;
|
||||
// print_r($product);die;
|
||||
|
||||
|
||||
|
||||
$PurchaseOrderChildModel = new PurchaseOrderChildModel();
|
||||
$purchase_product=$PurchaseOrderChildModel->where('purchase_order_id', $purchase_order_id)->findAll();
|
||||
$data['purchase_product']=$purchase_product;
|
||||
|
||||
}
|
||||
// echo "<pre>";
|
||||
// print_r($data);die;
|
||||
echo view('return_order_form',$data);
|
||||
}
|
||||
|
||||
public function add_purchase()
|
||||
{
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
$ProductModel = new ProductModel();
|
||||
$PurchaseOrderChildModel = new PurchaseOrderChildModel();
|
||||
$data = [
|
||||
'vendor_id' => $this->request->getPost('vendor_id'),
|
||||
'order_date' => $this->request->getPost('order_date'),
|
||||
'contact_person_name' => $this->request->getPost('contact_person_name'),
|
||||
'contact_person_mobile'=> $this->request->getPost('contact_person_mobile'),
|
||||
'status'=> $this->request->getPost('purchase_status'),
|
||||
'billing_address' => $this->request->getPost('billing_address'),
|
||||
'billing_state' => $this->request->getPost('billing_state'),
|
||||
'billing_city' => $this->request->getPost('billing_city'),
|
||||
'billing_postal_code' => $this->request->getPost('billing_postal_code'),
|
||||
'shipping_address' => $this->request->getPost('shipping_address'),
|
||||
'shipping_state' => $this->request->getPost('shipping_state'),
|
||||
'shipping_city' =>$this->request->getPost('shipping_city'),
|
||||
'shipping_postal_code' => $this->request->getPost('shipping_postal_code'),
|
||||
'return_date' => $this->request->getPost('return_date') ? $this->request->getPost('return_date') : '',
|
||||
'terms_condition' => $this->request->getPost('terms_condition'),
|
||||
'branch_id'=> $this->session->get('logged_user_branch_id'),
|
||||
];
|
||||
|
||||
// print_r($data);die;
|
||||
$purchase_order_id = $this->request->getPost('purchase_order_id');
|
||||
// echo $purchase_order_id;die;
|
||||
if (!empty($purchase_order_id)) {
|
||||
|
||||
$PurchaseOrderModel->update($purchase_order_id, $data);
|
||||
} else {
|
||||
|
||||
$PurchaseOrderModel->insert($data);
|
||||
$purchase_order_id = $PurchaseOrderModel->getInsertID();
|
||||
}
|
||||
$orderNumber = 'PO' . str_pad($purchase_order_id, 8, '0', STR_PAD_LEFT);
|
||||
// print_r($orderNumber);die;
|
||||
// Update sales order with generated order number
|
||||
$PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
|
||||
// print_r();die;
|
||||
// Prepare data for sales order product
|
||||
$product_ids = $this->request->getPost('item_details');
|
||||
$quantities = $this->request->getPost('quantity');
|
||||
// $discounts = $this->request->getPost('discount_amount');
|
||||
// $discount_types = $this->request->getPost('discount_type');
|
||||
$amounts = $this->request->getPost('amount');
|
||||
$itemtax=$this->request->getPost('item-tax');
|
||||
$unitprice=$this->request->getPost('unit-price');
|
||||
$selected_items=$this->request->getPost('selected_items');
|
||||
$purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
|
||||
// print_r($selected_items);die;
|
||||
|
||||
// print_r($status);die;
|
||||
$status = $this->request->getPost('purchase_status');
|
||||
foreach ($product_ids as $key => $product_id) {
|
||||
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
|
||||
$selected_item= isset($selected_items[$key]) ? $selected_items[$key] : 0;
|
||||
// print_r($selected_item);die;
|
||||
if ($status == 'Released' && $selected_item == 1) {
|
||||
$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;
|
||||
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
|
||||
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
|
||||
|
||||
// $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
|
||||
// print_r($discount_type);die;
|
||||
$child_data = [
|
||||
'purchase_order_id' => $purchase_order_id,
|
||||
'product_id' => $product_id,
|
||||
'qty' => $qty,
|
||||
// 'discount' => $discount,
|
||||
// 'discount_type' => $discount_type,
|
||||
'net_price'=>$rate,
|
||||
'tax'=>$tax,
|
||||
'amount' => $amount,
|
||||
'is_selected'=>$selected_item,
|
||||
'isactive'=>1,
|
||||
];
|
||||
// print_r($child_data);die;
|
||||
if (!empty($purchase_order_child_id[$key])) {
|
||||
|
||||
// print_r($purchase_order_child_id[$key]);die;
|
||||
$PurchaseOrderChildModel->update($purchase_order_child_id[$key], $child_data);
|
||||
|
||||
} else {
|
||||
$PurchaseOrderChildModel->insert($child_data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return redirect()->to('purchase_index');
|
||||
}
|
||||
private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
|
||||
{
|
||||
|
||||
// Fetch current product quantity
|
||||
$product = $ProductModel->find($product_id);
|
||||
$current_qty = $product['qty_stock'];
|
||||
|
||||
// Calculate updated quantity
|
||||
$new_qty = $current_qty + $sold_qty;
|
||||
|
||||
// Update quantity in Product table
|
||||
$ProductModel->update($product_id, ['qty_stock' => $new_qty]);
|
||||
}
|
||||
|
||||
public function delete_purchase($purchase_order_id)
|
||||
{
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
$where = ['purchase_order_id' => $purchase_order_id, 'isactive' => 1 ]; // Assuming 'isactive' is a column in your database
|
||||
$existingPurchase = $PurchaseOrderModel->where($where)->first();
|
||||
|
||||
if ($existingPurchase) {
|
||||
$data['isactive'] = 0;
|
||||
|
||||
if ($PurchaseOrderModel->update($purchase_order_id, $data)) {
|
||||
session()->setFlashdata('success', 'Deleted successfully.');
|
||||
$this->logger->info("Purchase Order: has been Inactivated successfully. Inactivated ID = ".$purchase_order_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return redirect()->to('purchase_index');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function get_vendor($vendor_id)
|
||||
{
|
||||
|
||||
$VendorModel = new VendorModel();
|
||||
|
||||
$products =$VendorModel->where('vendor_id',$vendor_id)->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray();
|
||||
|
||||
|
||||
return json_encode($products);
|
||||
|
||||
}
|
||||
public function getVendorProducts()
|
||||
{
|
||||
// Retrieve make_id and model_id from the request
|
||||
// $makeId = $this->request->getPost('');
|
||||
$vendorId = $this->request->getPost('vendor_id');
|
||||
|
||||
// Encode the modelId before searching
|
||||
$encodedVendorId = json_encode([$vendorId]);
|
||||
|
||||
// Load the ProductModel
|
||||
$productModel = new ProductModel();
|
||||
|
||||
// Query the database to find the product based on make_id and model_id
|
||||
$product = $productModel
|
||||
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
|
||||
->findAll();
|
||||
|
||||
// print_r($product);die;
|
||||
if($product){
|
||||
// Send JSON response
|
||||
return $this->response->setJSON(['product'=>$product] );
|
||||
} else {
|
||||
// If product is not found, return an empty response or appropriate message
|
||||
return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
|
||||
}
|
||||
}
|
||||
public function delete_purchase_product()
|
||||
{
|
||||
$purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
|
||||
|
||||
if (!empty($purchase_order_child_id)) {
|
||||
$PurchaseOrderChildModel = new PurchaseOrderChildModel();
|
||||
$data['isactive'] = 0;
|
||||
|
||||
if ($PurchaseOrderChildModel->update($purchase_order_child_id, $data)) {
|
||||
// Return success response
|
||||
return $this->response->setJSON(['success' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
// Return error response if deletion fails
|
||||
return $this->response->setJSON(['success' => false]);
|
||||
}
|
||||
public function download_purchase_invoice($purchase_order_id)
|
||||
{
|
||||
// echo "hello"; die;
|
||||
// Fetch the invoice data based on $invoice_id
|
||||
$model = new PurchaseOrderModel();
|
||||
$data = $model->getPurchasePdf($purchase_order_id);
|
||||
|
||||
$items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||
|
||||
|
||||
|
||||
// print_r($items);die();
|
||||
|
||||
// print_r($invoiceItems);die();
|
||||
|
||||
// Create an mPDF object
|
||||
$mpdf = new Mpdf([
|
||||
'mode' => '',
|
||||
'format' => 'A5',
|
||||
'default_font_size' => 0,
|
||||
'default_font' => '',
|
||||
|
||||
// 'margin_right' => 1,
|
||||
'margin_top' => 6,
|
||||
'margin_bottom' => 6,
|
||||
'margin_header' => 6,
|
||||
'margin_footer' =>-30,
|
||||
'orientation' => 'P',
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
|
||||
// Set PDF properties
|
||||
$mpdf->SetTitle('Invoice');
|
||||
$mpdf->SetAuthor($data[0]->branch_name);
|
||||
$mpdf->SetCreator('');
|
||||
|
||||
|
||||
|
||||
// Generate the PDF content (HTML)
|
||||
// if ($data[0]->status === 'Draft') {
|
||||
// // Set the watermark text and options
|
||||
// $mpdf->SetWatermarkText('Draft');
|
||||
// $mpdf->showWatermarkText = true;
|
||||
// }
|
||||
// if ($data[0]->status === 'Cancelled') {
|
||||
// // Set the watermark text and options
|
||||
// $mpdf->SetWatermarkText('Cancelled');
|
||||
// $mpdf->showWatermarkText = true;
|
||||
// }
|
||||
// if ($data[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_purchase_template', ['sales' => $data,'items'=>$items]);
|
||||
// echo $html;die;
|
||||
// Load HTML into the mPDF instance
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Output the PDF to the browser for download
|
||||
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
||||
}
|
||||
}
|
||||
@ -134,7 +134,7 @@ $VehicleModel = new VehicleModel();
|
||||
'isactive' => 1, // Assuming this is a default value or handled separately
|
||||
'branch_id'=> $this->session->get('logged_user_branch_id'),
|
||||
];
|
||||
// print_r($data);die;
|
||||
// print_r($data);die;
|
||||
// Insert or update sales order
|
||||
$sales_order_id = $this->request->getPost('sales_order_id');
|
||||
if (!empty($sales_order_id)) {
|
||||
|
||||
@ -5,7 +5,7 @@ class PurchaseOrderChildModel extends Model
|
||||
{
|
||||
protected $table = 'purchase_order_child';
|
||||
protected $primaryKey = 'purchase_order_child_id';
|
||||
protected $allowedFields = ['purchase_order_child_id','purchase_order_id','product_id','qty','total','tax','net_price','amount','discount_type','selling_price','discount','isactive'];
|
||||
protected $allowedFields = ['purchase_order_child_id','is_selected','purchase_order_id','product_id','qty','total','tax','net_price','amount','discount_type','selling_price','discount','isactive'];
|
||||
|
||||
|
||||
}
|
||||
@ -5,7 +5,7 @@ class PurchaseOrderModel extends Model
|
||||
{
|
||||
protected $table = 'purchase_order';
|
||||
protected $primaryKey = 'purchase_order_id';
|
||||
protected $allowedFields = ['purchase_order_id','order_number','vendor_id','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive','order_date','contact_person_name','branch_id','contact_person_mobile','description','subtotal','tax','total'];
|
||||
protected $allowedFields = ['purchase_order_id','bill_number','return_date','order_number','vendor_id','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive','order_date','contact_person_name','branch_id','contact_person_mobile','description','subtotal','tax','total'];
|
||||
|
||||
public function getPurchaseOrdersWithProducts($logged_user_branch_id)
|
||||
{
|
||||
@ -25,4 +25,41 @@ class PurchaseOrderModel extends Model
|
||||
// Get the results
|
||||
return $this->findAll();
|
||||
}
|
||||
public function getPurchasePdf($purchase_order_id){
|
||||
return $this->db->table('purchase_order')
|
||||
->where('purchase_order_id', $purchase_order_id)
|
||||
|
||||
->join('branches as B','B.branch_id = purchase_order.branch_id','left')
|
||||
->join('vendor as V','V.vendor_id = purchase_order.vendor_id','left')
|
||||
->select('purchase_order.*')
|
||||
->select('V.vendor_name,V.contact_person_mobile1,V.address as vendor_address,V.city as vendor_city,V.state,V.postal_code as vendor_postal,B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.mobile_no as company_mobile_no')
|
||||
|
||||
->get()
|
||||
->getResult();
|
||||
}
|
||||
public function getPurchaseOrderProductsForPdf($purchase_order_id)
|
||||
{
|
||||
// Select required fields from the sales_order_product table
|
||||
$result = $this->db->table('purchase_order_child')
|
||||
->where('purchase_order_child.purchase_order_id', $purchase_order_id)
|
||||
->join('products', 'products.product_id = purchase_order_child.product_id')
|
||||
->select('purchase_order_child.*, products.product_name')
|
||||
->get()
|
||||
->getResult();
|
||||
|
||||
return $result;
|
||||
}
|
||||
public function getdata($logged_user_branch_id)
|
||||
{
|
||||
$result = $this->db->table('purchase_order')
|
||||
|
||||
->join('purchase_order_child','purchase_order_child.product_id=purchase_order_child.product_id')
|
||||
->join('products', 'products.product_id = purchase_order_child.product_id')
|
||||
->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id')
|
||||
->select('purchase_order_child.*,vendor.*, products.product_name')
|
||||
->get()
|
||||
->getResult();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
9
app/Models/ReturnModel.php
Normal file
9
app/Models/ReturnModel.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
class ReturnModel extends Model
|
||||
{
|
||||
protected $table = 'return_order';
|
||||
protected $primaryKey = 'return_order_id';
|
||||
protected $allowedFields = ['return_order_id','purchase_order_id','return_date','is_selected','order_number','vendor_id','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive','order_date','contact_person_name','branch_id','contact_person_mobile','description','subtotal','tax','total'];
|
||||
}
|
||||
@ -171,7 +171,7 @@ p {
|
||||
<th><?php echo ($value->order_number) ? 'Order # ' . $value->order_number : 'Invoice # ' . $value->invoice_number; ?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Invoice Date : <?= date('d-m-Y', strtotime($value->created_at)) ?></th>
|
||||
<th>Date : <?= date('d-m-Y', strtotime($value->created_at)) ?></th>
|
||||
|
||||
</tr>
|
||||
|
||||
|
||||
302
app/Views/invoice_purchase_template.php
Normal file
302
app/Views/invoice_purchase_template.php
Normal file
@ -0,0 +1,302 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
/* Add your CSS styles here to format the invoice for mPDF */
|
||||
body {
|
||||
|
||||
font-family: 'Times New Roman', Times, sans-serif;
|
||||
|
||||
font-size: 12px; /* Change this value to your desired font size */
|
||||
}
|
||||
|
||||
/* Style for the main table with border */
|
||||
table.main-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: -0.5px solid black; /* Add a border around the entire invoice */
|
||||
}
|
||||
|
||||
table.main-table th,
|
||||
table.main-table td {
|
||||
border: none; /* Remove borders from all cells inside the main table */
|
||||
|
||||
}
|
||||
|
||||
/* Style for the table containing business details */
|
||||
table.business-details-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table.business-details-table td {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Style for the business logo and title */
|
||||
.business-logo-container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
img.business-logo {
|
||||
max-width: 200px; /* Adjust the size of the logo */
|
||||
}
|
||||
|
||||
/* Style for the business name */
|
||||
.business-name {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* Style for the table containing invoice info */
|
||||
table.invoice-info-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.invoice-info-table th,
|
||||
table.invoice-info-table td {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Style for the addresses table */
|
||||
table.addresses-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.addresses-table th {
|
||||
text-align: left;
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
/* Style for the billing and shipping addresses */
|
||||
.billing-address {
|
||||
width: 50%;
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
/* Style for the invoice-related table */
|
||||
table.invoice-related-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table.invoice-related-table th,
|
||||
table.invoice-related-table td {
|
||||
border: none; /* Remove borders from all cells in the invoice items table */
|
||||
padding: 8px;
|
||||
text-align: center; /* Center-align text in cells */
|
||||
}
|
||||
|
||||
table.invoice-related-table th {
|
||||
background-color: #f2f2f2;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Style for the business stamp and terms */
|
||||
.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; /* Add a border around the subtotal table */
|
||||
}
|
||||
|
||||
.subtotal-table th,
|
||||
.subtotal-table td {
|
||||
border: none; /* Remove borders from cells inside the subtotal table */
|
||||
padding: 8px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.subtotal-table th {
|
||||
background-color: #f2f2f2;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.subtotal-table td:last-child {
|
||||
font-weight: bold; /* Make the last column (total values) bold */
|
||||
}
|
||||
td.invoice-number {
|
||||
font-size: 18px; /* Increase font size to your desired value */
|
||||
/* Highlight background color */
|
||||
font-weight: bold; /* Make the text bold */
|
||||
}
|
||||
p {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="main-table">
|
||||
<tr>
|
||||
<td>
|
||||
<table class="business-details-table">
|
||||
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
<tr>
|
||||
<td class="business-logo-container"style="font-size: 16px;font-weight: bold;">
|
||||
THE MECHANIC
|
||||
<!-- <img src="https://vijayabharathambooks.com/wp-content/uploads/2021/09/vijaya-bharatham-logo-8pt.png" alt="Business Logo" class="business-logo"> -->
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p><?= $value->company_address ?>,<br>
|
||||
<?= $value->company_city ?>,
|
||||
<?= $value->company_state ?>
|
||||
<?= $value->company_postal_code ?>.</p>
|
||||
|
||||
<p><?= $value->company_mobile_no ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table class="invoice-info-table">
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
<tr>
|
||||
<th><?php echo ($value->order_number) ? 'Order # ' . $value->order_number : 'Invoice # ' . $value->invoice_number; ?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Date : <?= date('d-m-Y', strtotime($value->created_at)) ?></th>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Status :<?= $value->status ?></th>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="addresses-table">
|
||||
<tr >
|
||||
<th class="billing-address">Vendor Address</th>
|
||||
<th class="shipping-address">Shipping Address</th>
|
||||
</tr>
|
||||
<tr >
|
||||
<td class="billing-address">
|
||||
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
<?= $value->vendor_name ?><br>
|
||||
<?= $value->vendor_address != '' ? $value->vendor_address." , <br>" : ''; ?>
|
||||
<?= $value->vendor_city ?>
|
||||
<?php if ($value->vendor_postal!=0): ?>
|
||||
<?= $value->vendor_postal ?><br>
|
||||
<?php endif; ?>
|
||||
<?= $value->contact_person_mobile1." ." ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
<tr>
|
||||
<td class="shipping-address">
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
|
||||
<?= $value->billing_address != '' ? $value->vendor_address." , <br>" : ''; ?>
|
||||
<?= $value->billing_city ?>
|
||||
<?php if ($value->billing_postal_code!=0): ?>
|
||||
<?= $value->billing_postal_code ?><br>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br> <br>
|
||||
<table class="invoice-related-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>S.no</th>
|
||||
<th>Item Name</th>
|
||||
|
||||
|
||||
<th>Qty</th>
|
||||
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $serialNumber = 1; ?>
|
||||
<?php foreach ($items as $item) : ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?= $serialNumber++; ?>
|
||||
|
||||
</td>
|
||||
|
||||
<td><?= $item->product_name ?></td>
|
||||
|
||||
<td><?= $item->qty ?></td>
|
||||
|
||||
|
||||
|
||||
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="subtotal-table">
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
<tr>
|
||||
<td colspan="5" align="right"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5" align="right"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<!-- -->
|
||||
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
<td colspan="5" align="right"></td>
|
||||
</tr>
|
||||
<?php if ($value->status === 'Approved'): ?>
|
||||
<tr>
|
||||
<td colspan="5" align="right">Paid : ₹<?= number_format($value->total_amount, 2, '.', ',') ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<div class="business-stamp">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="terms">
|
||||
|
||||
|
||||
<p style=text-align:left><?= $value->terms_condition;?></p>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- ... (your existing HTML template) -->
|
||||
|
||||
<!-- Add this to the end of your HTML template -->
|
||||
|
||||
|
||||
<!-- <img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png" /> -->
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -179,6 +179,14 @@
|
||||
<i class="fas fa-angle-double-up"></i>
|
||||
<span> Reorder Level Products </span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?php echo base_url('return_order') ?>">
|
||||
<i class="fas fa-angle-double-up"></i>
|
||||
<span> Return Products </span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="make" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<select class="form-control vendor-select" name="vendor_id" id="vendor_id">
|
||||
<select class="form-control vendor-select SelExample" name="vendor_id" id="vendor_id" <?php echo in_array($vendor_id, array_column($vendor, 'vendor_id')) ? 'disabled' : ''; ?>>
|
||||
<option value="0">Select Vendor</option>
|
||||
<?php foreach ($vendor as $item): ?>
|
||||
<option value="<?= $item['vendor_id'] ?>" <?= isset($item['vendor_id']) && $vendor_id == $item['vendor_id'] ? 'selected' : '' ?>>
|
||||
@ -48,18 +48,40 @@
|
||||
<input type="text" class="form-control" name="contact_person_mobile" id="contact_person_mobile" placeholder="Contact Person Mobile" value="<?= isset($purchase['contact_person_mobile']) ? $purchase['contact_person_mobile'] : '' ?>"maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="purchase_status" class="col-form-label">Purchase Status<span class="text-danger">*</span></label>
|
||||
<select name="purchase_status" id="purchase_status" class="form-control">
|
||||
<option value="Draft" <?= isset($purchase['status']) && $purchase['status'] == 'Draft' ? 'selected' : '' ?>>Draft</option>
|
||||
<option value="Cancel" <?= isset($purchase['status']) && $purchase['status'] == 'Cancel' ? 'selected' : '' ?>>Cancel</option>
|
||||
<option value="Released" <?= isset($purchase['status']) && $purchase['status'] == 'Released' ? 'selected' : '' ?>>Released</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Order Date</label>
|
||||
<input type="date" class="form-control" name="order_date" id="order_date" value="<?= empty($purchase['order_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['order_date'])) ?>" readonly>
|
||||
</div>
|
||||
<?php if (!empty($purchase["status"])): ?>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Return Date</label>
|
||||
<input type="date" class="form-control" name="return_date" id="return_date" value="<?= empty($purchase['return_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['return_date'])) ?>" >
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>
|
||||
<?php if (isset($purchase['status']) && $purchase['status'] !== ''): ?>
|
||||
(<?= $purchase['status'] ?>)
|
||||
<?php endif; ?></label>
|
||||
<select class="form-control status-select" name="purchase_status" required data-toggle="select2">
|
||||
<?php if (isset($purchase['status'])): ?>
|
||||
<?php if ($purchase['status'] === 'Cancel'): ?>
|
||||
<option value="">Select Status</option>
|
||||
<option value="Received" <?= $purchase['status'] === 'Received' ? 'selected' : '' ?>>Received</option>
|
||||
<?php else: ?>
|
||||
<option value="">Select Status</option>
|
||||
<option value="Received" <?= $purchase['status'] === 'Received' ? 'selected' : '' ?>>Received</option>
|
||||
<option value="Cancel" <?= $purchase['status'] === 'Cancel' ? 'selected' : '' ?>>Cancel</option>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<option value="PO Issued" selected>PO Issued</option>
|
||||
<!-- <option value="Paid">Paid</option> -->
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<h4 class="header-title">Billing Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
@ -99,8 +121,15 @@
|
||||
<label for="Shipping Postal Code" class="col-form-label">Shipping Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_postal_code" id="shipping_postal_code" placeholder="Shipping Pin Code"value="<?= isset($branch['postal_code']) ? $branch['postal_code'] : (isset($purchase['shipping_postal_code']) ? $purchase['shipping_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
|
||||
</div><br>
|
||||
|
||||
<?php if (!empty($purchase["status"])): ?>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="shipping_address" class="col-form-label">Bill Number<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="bill_number" id="bill_number" placeholder="Bill Number"value="<?= isset($purchase['bill_number']) ? $purchase['bill_number'] : '' ?>" required>
|
||||
</div> </div>
|
||||
<?php endif; ?>
|
||||
<div class="form-row" id="itemTableContainer">
|
||||
<div class="form-group col-md-12">
|
||||
<h4>Item Details</h4>
|
||||
@ -111,10 +140,10 @@
|
||||
<tr>
|
||||
<th>Item Details</th>
|
||||
<th>Qty</th>
|
||||
<th>Rate</th>
|
||||
<th>Tax</th>
|
||||
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
|
||||
<th>Amount</th>
|
||||
<?php if (!empty($purchase["status"])): ?>
|
||||
<th>Received</th>
|
||||
<th>Amount</th>
|
||||
<?php endif; ?>
|
||||
<th hidden></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
@ -126,7 +155,8 @@
|
||||
<?php foreach ($purchase_product as $purchasechild) :
|
||||
if ($purchasechild['isactive'] == 1) : ?>
|
||||
<tr>
|
||||
<td>
|
||||
<td style="width:10%;">
|
||||
|
||||
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
|
||||
<option value="">Select a Product</option>
|
||||
<?php foreach ($product as $value) : ?>
|
||||
@ -138,29 +168,17 @@
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<td style="width:5%;">
|
||||
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-rate" name="unit-price[]" readonly value="<?= isset($purchasechild['net_price']) ? $purchasechild['net_price'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($purchasechild['tax']) ? $purchasechild['tax'] : '' ?>">
|
||||
</td>
|
||||
<!-- <td style="width:12%;">
|
||||
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($purchasechild['discount']) ? $purchasechild['discount'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<select class="form-control item-discount-type" name="discount_type[]">
|
||||
<option value="₹" <?= isset($purchasechild['discount_type']) && $purchasechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
|
||||
<option value="%" <?= isset($purchasechild['discount_type']) && $purchasechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
|
||||
</select>
|
||||
</td> -->
|
||||
<td style="width:12%;">
|
||||
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($purchasechild['amount']) ? $purchasechild['amount'] : '' ?>">
|
||||
<td style="width:2%;">
|
||||
<input type="checkbox" class="form-control-check-input" name="selected_items[]" value="<?= ($purchasechild['is_selected']) ? '0' : '1' ?>" <?php echo ($purchasechild['is_selected']) ? 'checked' : '1'; ?>>
|
||||
</td>
|
||||
<td style="width:5%;">
|
||||
<input type="number" class="form-control item-quantity" name="amount[]" value="<?= isset($purchasechild['amount']) ? $purchasechild['amount'] : '' ?>">
|
||||
</td>
|
||||
<td hidden><input type="hidden" value="<?= isset($purchasechild['purchase_order_child_id']) ? $purchasechild['purchase_order_child_id'] : '' ?>"name="purchase_order_child_id[]"></td>
|
||||
<td style="width:12%;">
|
||||
<td style="width:5%;">
|
||||
<center><i class="fa fa-trash remove-item"></i></center>
|
||||
</td>
|
||||
</tr>
|
||||
@ -170,46 +188,19 @@
|
||||
<!-- You can add more rows as needed using JavaScript -->
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if (empty($purchase["status"])): ?>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<!-- Show the "Add More Item" button only if invoice_type is not 1 -->
|
||||
<a class="btn" id="addItem">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="offset-md-7 col-md-5 card">
|
||||
<div class="card-body">
|
||||
<h4>Calculation</h4>
|
||||
<div class="form-group">
|
||||
<label for="subtotal">Subtotal</label>
|
||||
<input type="text" class="form-control" id="subtotal" name="sub_total" value="<?= isset($sales['subtotal']) ? $sales['subtotal'] : '' ?>"readonly >
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="invoicetax">Tax Amount<span id=""></span></label>
|
||||
|
||||
<input type="text" class="form-control" id="invoicetax" name="invoice_tax" readonly value="<?= isset($sales['tax']) ? $sales['tax'] : '' ?>">
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- <div class="form-group">
|
||||
<label for="discount">Discount Amount</label>
|
||||
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" min="0" readonly value="<?= isset($sales['discount']) ? $sales['discount'] : '' ?>" >
|
||||
</div> -->
|
||||
<div class="form-group">
|
||||
<label for="grandtotal">Total</label>
|
||||
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($sales['total']) ? $sales['total'] : '' ?>">
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="header-title">Terms & Condition :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-12">
|
||||
@ -220,11 +211,11 @@
|
||||
<?= isset($sales['terms_condition']) ? $sales['terms_condition'] : 'Please check the products properly before purchase. Products once sold cannot be returned.' ?>
|
||||
</textarea>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($sales['status']) || $sales['status'] !== 'Paid') : ?>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($purchase['status']) || $purchase['status'] !== 'Released') : ?>
|
||||
<button type="submit" id="editaddbutton"class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
@ -236,48 +227,50 @@
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
productarray = [];
|
||||
$(document).ready(function() {
|
||||
// Event listener for vehicle selection change
|
||||
// Function to fetch products based on vendor ID
|
||||
function fetchVendorProducts(vendorId) {
|
||||
if (vendorId !== '') {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getVendorProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
vendor_id: vendorId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
// Assuming response contains product data
|
||||
// You can handle product data as per your requirements
|
||||
// For example, updating UI or populating a dropdown with products
|
||||
// Here, I'm just logging the product array to the console
|
||||
productarray = response.product;
|
||||
console.log(productarray);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Vendor ID not found');
|
||||
}
|
||||
}
|
||||
|
||||
// Event listener for vendor selection change
|
||||
$('.vendor-select').change(function() {
|
||||
var vendorId = $(this).val();
|
||||
|
||||
if (vendorId !== '') {
|
||||
// Find the selected vehicle
|
||||
var selectedVehicle = vendors.find(function(vendor) {
|
||||
return vendor.vendor_id == vendorId;
|
||||
});
|
||||
|
||||
// Extract makeId from the selected vehicle
|
||||
|
||||
|
||||
// Make sure makeId exists
|
||||
if (vendorId !== undefined) {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getVendorProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
|
||||
vendor_id: vendorId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
productarray = response.product;
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Make ID not found for the selected vehicle');
|
||||
}
|
||||
}
|
||||
fetchVendorProducts(vendorId);
|
||||
});
|
||||
|
||||
// Edit scenario: Populate products based on stored vendor ID
|
||||
var storedVendorId = "<?php echo isset($purchase['vendor_id']) ? $purchase['vendor_id'] : ''; ?>";
|
||||
if (storedVendorId !== '') {
|
||||
// Trigger change event to fetch products based on stored vendor ID
|
||||
$('#vendor_id').val(storedVendorId).change();
|
||||
}
|
||||
});
|
||||
|
||||
<?php
|
||||
@ -327,7 +320,7 @@ $(document).ready(function() {
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(0);
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
||||
|
||||
// Find product details from JSON
|
||||
var product = products.find(function(item) {
|
||||
@ -428,10 +421,8 @@ $(document).ready(function() {
|
||||
|
||||
newRow += '</select></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
|
||||
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
|
||||
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
||||
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
|
||||
'<td hidden><input type="hidden"></td>' +
|
||||
|
||||
|
||||
'<td><center><i class="fa fa-trash remove-item"></i></center></td>' +
|
||||
'</tr>';
|
||||
|
||||
@ -451,6 +442,18 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script>
|
||||
// Validate form before submission
|
||||
$('form').submit(function() {
|
||||
var status = $('select[name="purchase_status"]').val();
|
||||
if (status === "") {
|
||||
alert("Please select a status.");
|
||||
return false; // Prevent form submission
|
||||
}
|
||||
// If all validations pass, allow form submission
|
||||
return true;
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Event listener for removing item
|
||||
@ -481,52 +484,26 @@ $(document).on('click', '.remove-item', function() {
|
||||
});
|
||||
$(document).ready(function() {
|
||||
// Event listener for customer selection change
|
||||
$('.vehicle-select').change(function() {
|
||||
|
||||
var vehicleId = $(this).val();
|
||||
if (vehicleId !== '') {
|
||||
$('.vendor-select').change(function() {
|
||||
console.log(vendors);
|
||||
var vendorId = $(this).val();
|
||||
if (vendorId !== '') {
|
||||
// Find the selected client in the client data
|
||||
var selectedClient = vehicles.find(function(vehicle) {
|
||||
return vehicle.vehicle_id == vehicleId;
|
||||
var selctedVendor = vendors.find(function(vendor) {
|
||||
return vendor.vendor_id == vendorId;
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('input[name="client_id"]').val(selectedClient.client_name);
|
||||
$('input[name="billing_address"]').val(selectedClient.address);
|
||||
$('input[name="billing_address"]').val(selectedClient.address);
|
||||
$('input[name="city"]').val(selectedClient.city);
|
||||
$('input[name="state"]').val(selectedClient.state);
|
||||
$('input[name="country"]').val(selectedClient.country);
|
||||
$('input[name="mobile_no"]').val(selectedClient.mobile_no);
|
||||
$('input[name="postalcode"]').val(selectedClient.postal_code);
|
||||
$('input[name="contact_person_name"]').val(selctedVendor.contact_person_name1);
|
||||
$('input[name="contact_person_mobile"]').val(selctedVendor.contact_person_mobile1);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Event listener for customer selection change
|
||||
$('.cleint-select').change(function() {
|
||||
|
||||
var clientId = $(this).val();
|
||||
// console.log(vehicleId);
|
||||
if (clientId !== '') {
|
||||
// Find the selected client in the client data
|
||||
var selectedClients = clients.find(function(client) {
|
||||
return client.client_id == clientId;
|
||||
});
|
||||
|
||||
// Populate the billing address, city, state, country, and postal code fields
|
||||
|
||||
|
||||
$('input[id="clientMobile"]').val(selectedClients.mobile_no);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Define the clients array and populate it with data
|
||||
var vendors = <?php echo json_encode($vendor); ?>;
|
||||
@ -555,162 +532,28 @@ function initializeSelect2() {
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
// AJAX request to save client
|
||||
$('#saveVehcileBtn').click(function() {
|
||||
|
||||
var formType = $('#formType').val();
|
||||
console.log(formType);
|
||||
|
||||
var reg_no = $('#reg_no').val();
|
||||
var model = $('#model').val();
|
||||
var make = $('#make').val();
|
||||
|
||||
var clientName = $('#clientName').val();
|
||||
var clientMobile = $('#clientMobile').val();
|
||||
|
||||
var createclientName = $('#create-clientName').val();
|
||||
var createclientMobile = $('#create-clientMobile').val();
|
||||
var createclientType = $('#create-clientType').val();
|
||||
|
||||
if (formType == 'select')
|
||||
{
|
||||
var ifStatementCondition = "clientName !== '' && clientMobile !== '' && reg_no !== '' && model !== '' && make !== ''";
|
||||
} else {
|
||||
var ifStatementCondition = "createclientName !== '' && createclientMobile !== '' && createclientType !== '' && reg_no !== '' && model !== '' && make !== ''";
|
||||
}
|
||||
|
||||
console.log(ifStatementCondition);
|
||||
|
||||
if( eval(ifStatementCondition) ){
|
||||
|
||||
// Send AJAX request to save the client
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_vehicle'?>', // URL to your save_client method
|
||||
method: 'POST',
|
||||
data: {
|
||||
client_id: clientName,
|
||||
mobile_no: clientMobile,
|
||||
reg_no:reg_no,
|
||||
model:model,
|
||||
make:make,
|
||||
createclientName:createclientName,
|
||||
createclientMobile:createclientMobile,
|
||||
createclientType:createclientType,
|
||||
formType:formType,
|
||||
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$('#addVehicleModal').modal('hide');
|
||||
toastr.success("Vehicle saved successfully!");
|
||||
window.location.reload();
|
||||
|
||||
} else {
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving vehicle:', error);
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
}
|
||||
});
|
||||
|
||||
}else{
|
||||
toastr.warning("Please Fill All Data");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<script>
|
||||
$(".SelExample").select2();
|
||||
|
||||
// Event listener for change in make select dropdown
|
||||
$("#make").on('change', function() {
|
||||
var selected_makes = $(this).val(); // Get an array of selected make IDs
|
||||
// AJAX request to fetch models based on selected make IDs
|
||||
$.ajax({
|
||||
url: '<?= base_url("fetch_models") ?>', // URL to your controller method for fetching models
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { selected_makes: [selected_makes] },
|
||||
success: function(response) {
|
||||
// Clear existing options in model select dropdown
|
||||
$("#model").empty();
|
||||
$("#model").append('<option value=""> Select a Model </option>');
|
||||
// Populate model select dropdown with fetched models
|
||||
$.each(response, function(index, model) {
|
||||
$("#model").append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
|
||||
});
|
||||
|
||||
// Refresh select2 to reflect changes
|
||||
$("#model").trigger('change');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(error); // Log any errors to the console
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('reg_no').addEventListener('input', function(event) {
|
||||
var inputText = event.target.value;
|
||||
event.target.value = inputText.toUpperCase();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click', '#createClient', function() {
|
||||
$('.create').show();
|
||||
$('.select').hide();
|
||||
$('#formType').val('create');
|
||||
|
||||
$('#clientName').val('');
|
||||
$('#clientMobile').val('');
|
||||
|
||||
|
||||
});
|
||||
$(document).on('click', '#selectClient', function() {
|
||||
$('.select').show();
|
||||
$('.create').hide();
|
||||
$('#formType').val('select');
|
||||
|
||||
$('#create-clientName').val('');
|
||||
$('#create-clientMobile').val('');
|
||||
$('#create-clientType').val('');
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.select2-container .select2-selection--multiple .select2-selection__choice{
|
||||
padding: 5px 7px 5px 0 !important;
|
||||
color: #000000;
|
||||
|
||||
}
|
||||
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
||||
color:#ffffff;
|
||||
background-color: #526dee;
|
||||
background: #526dee!important;
|
||||
}
|
||||
.select2-container--default .select2-results__option{
|
||||
border-bottom: 1px solid #dddddd;
|
||||
.select2-container .select2-selection--single{
|
||||
height: 36px;
|
||||
border:1px solid #ced4da;
|
||||
}
|
||||
.select2-container--default .select2-results__option[aria-selected=true]{
|
||||
color: #000000;
|
||||
background-color: #3efba4;
|
||||
font-weight: 500;
|
||||
border-bottom: 1px solid #747474;
|
||||
.select2-container--default .select2-selection--single .select2-selection__rendered{
|
||||
line-height: 36px;
|
||||
}
|
||||
</style>
|
||||
.select2-container--default .select2-selection--single .select2-selection__arrow{
|
||||
top:4px;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
// Assuming you have an edit button with an ID 'editButton'
|
||||
$('#editaddbutton').click(function() {
|
||||
// Enable the vendor dropdown
|
||||
$('#vendor_id').prop('disabled', false);
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -1,4 +1,25 @@
|
||||
<?php include('layout/header.php'); ?>
|
||||
<style>
|
||||
.dataTables_wrapper button{
|
||||
background: #f1f5f7;
|
||||
color: #343a40;
|
||||
border-width: 0;
|
||||
}
|
||||
.dataTables_wrapper .dt-buttons{
|
||||
float:left;
|
||||
}
|
||||
.cancelled-status {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.created-status {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.paid-status {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@ -23,7 +44,7 @@
|
||||
|
||||
|
||||
|
||||
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100"
|
||||
<table id="datatable-buttons3" class="table table-striped dt-responsive nowrap w-100"
|
||||
style="width:100% !important;">
|
||||
<thead>
|
||||
|
||||
@ -31,12 +52,10 @@
|
||||
<th>Order Number</th>
|
||||
<th>Vendor Name</th>
|
||||
<th>Order Date</th>
|
||||
<th>Contact Person Name</th>
|
||||
<th>Contact Person Mobile</th>
|
||||
<th>Contact Person Details</th>
|
||||
<!-- <th>Contact Person Mobile</th> -->
|
||||
<th>Quantity</th>
|
||||
<th>Subtotal</th>
|
||||
<th>Tax</th>
|
||||
<th>Total</th>
|
||||
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
@ -49,21 +68,29 @@
|
||||
<td><?= $value['order_number']; ?></td>
|
||||
<td><?= $value['vendor_name']; ?></td>
|
||||
<td><?= date('j F Y', strtotime($value['order_date'])); ?></td>
|
||||
<td><?= $value['contact_person_name']; ?></td>
|
||||
<td><?= $value['contact_person_mobile']; ?></td>
|
||||
<td><?= $value['contact_person_name']; ?><br>
|
||||
<?= $value['contact_person_mobile']; ?>
|
||||
<td><?= $value['product_count']; ?></td>
|
||||
<td><?= $value['subtotal']; ?></td>
|
||||
<td><?= $value['tax']; ?></td>
|
||||
<td><?= $value['total']; ?></td>
|
||||
<td><?= $value['status']; ?></td>
|
||||
|
||||
<td class="<?php
|
||||
if ($value['status'] == 'Cancel') {
|
||||
echo 'cancelled-status';
|
||||
} elseif ($value['status'] == 'Draft') {
|
||||
echo 'created-status';
|
||||
} elseif ($value['status'] == 'Released') {
|
||||
echo 'paid-status';
|
||||
}
|
||||
?>">
|
||||
<?= $value['status']; ?>
|
||||
</td>
|
||||
|
||||
<!-- Call the model method -->
|
||||
|
||||
<td>
|
||||
<a href="<?= "new_purchase/" . $value['purchase_order_id']; ?>" class="edit-button"><i
|
||||
class="ri-pencil-line"></i></a>
|
||||
<a href="<?= "delete_purchase/" . $value['purchase_order_id']; ?>"
|
||||
class="delete-button"><i class="ri-delete-bin-line"></i></a>
|
||||
</td>
|
||||
<a href="<?= "new_purchase/" . $value['purchase_order_id']; ?>" class="edit-button" title="Edit"><i class="ri-pencil-line" style="font-size: 20px;"></i></a>
|
||||
<a href="<?= "delete_purchase/" . $value['purchase_order_id']; ?>" class="delete-button" title="Delete"><i class="ri-delete-bin-line" style="font-size: 20px;"></i></a>
|
||||
<a href="<?= "download_purchase_invoice/" . $value['purchase_order_id']; ?>" class="edit-button" title="Download"><i class="ri-download-2-fill" style="font-size: 20px;"></i></a>
|
||||
</td>
|
||||
|
||||
<?php endif?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@ -77,4 +104,52 @@
|
||||
</div> <!-- end col -->
|
||||
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#datatable-buttons3').DataTable({
|
||||
"order": [[2, 'desc']], // Set initial sorting to descending on the first column
|
||||
"dom": 'Bfrtip', // Show export buttons
|
||||
"buttons": [ {
|
||||
extend: 'pdfHtml5',
|
||||
title: 'Transaction', // Set your custom PDF title here
|
||||
text: 'PDF',
|
||||
customize: function(doc) {
|
||||
// You can further customize the PDF here if needed
|
||||
// doc.content[1].table.body.forEach(function(row) {
|
||||
// row.splice(0, 1); // Remove the first column (ID column)
|
||||
// });
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'print',
|
||||
title: 'Transaction', // Set your custom print title here
|
||||
text: 'Print',
|
||||
customize: function(win) {
|
||||
// You can further customize the print output here if needed
|
||||
// $(win.document.body).find('table').find('th:first-child, td:first-child').remove();
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'copy',
|
||||
text: 'Copy', // Set the title for the Copy button
|
||||
titleAttr: 'Copy', // Set the tooltip for the Copy button
|
||||
exportOptions: {
|
||||
// columns: ':not(:first-child)' // Exclude the first column (ID column)
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'csv',
|
||||
text: 'CSV', // Set the title for the CSV button
|
||||
title: 'Transaction', // Set your custom print title here
|
||||
exportOptions: {
|
||||
// columns: ':not(:first-child)' // Exclude the first column (ID column)
|
||||
}
|
||||
}], // Enable export options
|
||||
"language": {
|
||||
"search": "Search: " // Customize search label
|
||||
},
|
||||
"ordering": false
|
||||
});
|
||||
});
|
||||
</script>
|
||||
716
app/Views/reorder_level_form.php
Normal file
716
app/Views/reorder_level_form.php
Normal file
@ -0,0 +1,716 @@
|
||||
<?php include('layout/header.php'); ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box page-title-box-alt">
|
||||
<h4 class="page-title"><?php echo $page_name?></h4>
|
||||
<div class="page-title-right">
|
||||
<a href="<?= base_url() . "purchase_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
||||
<ol class="breadcrumb m-0">
|
||||
|
||||
</li>
|
||||
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
|
||||
<li class="breadcrumb-item active">Datatables</li> -->
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"></h4>
|
||||
<form action="<?= base_url() . "add_purchase"; ?>" method="post">
|
||||
<input type="hidden" id="purchase_order_id" name="purchase_order_id" value="<?= isset($purchase['purchase_order_id']) ? $purchase['purchase_order_id'] : '' ?>"readonly>
|
||||
<h4 class="header-title">Purchase Details :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="make" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<select class="form-control vendor-select" name="vendor_id" id="vendor_id">
|
||||
<option value="0">Select Vendor</option>
|
||||
<?php foreach ($vendor as $item): ?>
|
||||
<option value="<?= $item['vendor_id'] ?>" <?= isset($item['vendor_id']) && $vendor_id == $item['vendor_id'] ? 'selected' : '' ?>>
|
||||
<?= $item['vendor_name'] ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_name" class="col-form-label">Contact Person Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_name" id="contact_person_name" placeholder="Contact Person Name.."value="<?= isset($purchase['contact_person_name']) ? $purchase['contact_person_name'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_mobile" class="col-form-label">Contact Person Mobile<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_mobile" id="contact_person_mobile" placeholder="Contact Person Mobile" value="<?= isset($purchase['contact_person_mobile']) ? $purchase['contact_person_mobile'] : '' ?>"maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="purchase_status" class="col-form-label">Purchase Status<span class="text-danger">*</span></label>
|
||||
<select name="purchase_status" id="purchase_status" class="form-control">
|
||||
<option value="Draft" <?= isset($purchase['status']) && $purchase['status'] == 'Draft' ? 'selected' : '' ?>>Draft</option>
|
||||
<option value="Cancel" <?= isset($purchase['status']) && $purchase['status'] == 'Cancel' ? 'selected' : '' ?>>Cancel</option>
|
||||
<option value="Released" <?= isset($purchase['status']) && $purchase['status'] == 'Released' ? 'selected' : '' ?>>Released</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Order Date</label>
|
||||
<input type="date" class="form-control" name="order_date" id="order_date" value="<?= empty($purchase['order_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['order_date'])) ?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="header-title">Billing Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="billing_address" class="col-form-label">Billing Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_address" id="billing_address" placeholder="Billing Addresss"value="<?= isset($business['address']) ? $business['address'] : (isset($purchase['billing_address']) ? $purchase['billing_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="billing_state" class="col-form-label">Billing State</label>
|
||||
<input type="text" class="form-control" name="billing_state" id="billing_state" placeholder="Billing State"value="<?= isset($business['state']) ? $business['state'] : (isset($purchase['billing_state']) ? $purchase['billing_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing City" class="col-form-label">Billing City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_city" id="billing_city" placeholder="Billing City"value="<?= isset($business['city']) ? $business['city'] : (isset($purchase['billing_city']) ? $purchase['billing_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing Postal Code" class="col-form-label">Billing Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_postal_code" id="billing_postal_code" placeholder="Billing Pin Code"value="<?= isset($business['postal_code']) ? $business['postal_code'] : (isset($purchase['billing_postal_code']) ? $purchase['billing_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
|
||||
</div><br>
|
||||
<h4 class="header-title">Shipping Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="shipping_address" class="col-form-label">Shipping Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_address" id="shipping_address" placeholder="Shipping Addresss"value="<?= isset($branch['address']) ? $branch['address'] : (isset($purchase['shipping_address']) ? $purchase['shipping_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="shipping_state" class="col-form-label">Shipping State</label>
|
||||
<input type="text" class="form-control" name="shipping_state" id="shipping_state" placeholder="Shipping State"value="<?= isset($branch['state']) ? $branch['state'] : (isset($purchase['shipping_state']) ? $purchase['shipping_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping City" class="col-form-label">Shipping City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_city" id="shipping_city" placeholder="Shipping City"value="<?= isset($branch['city']) ? $branch['city'] : (isset($purchase['shipping_city']) ? $purchase['shipping_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping Postal Code" class="col-form-label">Shipping Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_postal_code" id="shipping_postal_code" placeholder="Shipping Pin Code"value="<?= isset($branch['postal_code']) ? $branch['postal_code'] : (isset($purchase['shipping_postal_code']) ? $purchase['shipping_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
</div><br>
|
||||
|
||||
<div class="form-row" id="itemTableContainer">
|
||||
<div class="form-group col-md-12">
|
||||
<h4>Item Details</h4>
|
||||
<br />
|
||||
|
||||
<table class="table table-bordered" id="itemTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Item Details</th>
|
||||
<th>Qty</th>
|
||||
<th>Rate</th>
|
||||
<th>Tax</th>
|
||||
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
|
||||
<th>Amount</th>
|
||||
<th hidden></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<!-- Dynamically add rows for item details -->
|
||||
<?php if (isset($purchase_product) && !empty($purchase_product)) : ?>
|
||||
<?php foreach ($purchase_product as $purchasechild) :
|
||||
if ($purchasechild['isactive'] == 1) : ?>
|
||||
<tr>
|
||||
<td>
|
||||
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
|
||||
<option value="">Select a Product</option>
|
||||
<?php foreach ($product as $value) : ?>
|
||||
<?php if ((int)$value["isactive"] === 1) : ?>
|
||||
<option value="<?= $value["product_id"] ?>" <?= isset($purchasechild['product_id']) && $purchasechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>>
|
||||
<?= $value["product_name"]; ?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-rate" name="unit-price[]" readonly value="<?= isset($purchasechild['net_price']) ? $purchasechild['net_price'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($purchasechild['tax']) ? $purchasechild['tax'] : '' ?>">
|
||||
</td>
|
||||
<!-- <td style="width:12%;">
|
||||
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($purchasechild['discount']) ? $purchasechild['discount'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<select class="form-control item-discount-type" name="discount_type[]">
|
||||
<option value="₹" <?= isset($purchasechild['discount_type']) && $purchasechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
|
||||
<option value="%" <?= isset($purchasechild['discount_type']) && $purchasechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
|
||||
</select>
|
||||
</td> -->
|
||||
<td style="width:12%;">
|
||||
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($purchasechild['amount']) ? $purchasechild['amount'] : '' ?>">
|
||||
</td>
|
||||
<td hidden><input type="hidden" value="<?= isset($purchasechild['purchase_order_child_id']) ? $purchasechild['purchase_order_child_id'] : '' ?>"name="purchase_order_child_id[]"></td>
|
||||
<td style="width:12%;">
|
||||
<center><i class="fa fa-trash remove-item"></i></center>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<!-- You can add more rows as needed using JavaScript -->
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<!-- Show the "Add More Item" button only if invoice_type is not 1 -->
|
||||
<a class="btn" id="addItem">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="offset-md-7 col-md-5 card">
|
||||
<div class="card-body">
|
||||
<h4>Calculation</h4>
|
||||
<div class="form-group">
|
||||
<label for="subtotal">Subtotal</label>
|
||||
<input type="text" class="form-control" id="subtotal" name="sub_total" value="<?= isset($sales['subtotal']) ? $sales['subtotal'] : '' ?>"readonly >
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="invoicetax">Tax Amount<span id=""></span></label>
|
||||
|
||||
<input type="text" class="form-control" id="invoicetax" name="invoice_tax" readonly value="<?= isset($sales['tax']) ? $sales['tax'] : '' ?>">
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- <div class="form-group">
|
||||
<label for="discount">Discount Amount</label>
|
||||
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" min="0" readonly value="<?= isset($sales['discount']) ? $sales['discount'] : '' ?>" >
|
||||
</div> -->
|
||||
<div class="form-group">
|
||||
<label for="grandtotal">Total</label>
|
||||
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($sales['total']) ? $sales['total'] : '' ?>">
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="header-title">Terms & Condition :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-12">
|
||||
|
||||
|
||||
<label for="inputPassword4" class="col-form-label">Terms & Condition</label>
|
||||
<textarea class="form-control" name="terms_condition" placeholder="Terms & Condition" >
|
||||
<?= isset($sales['terms_condition']) ? $sales['terms_condition'] : 'Please check the products properly before purchase. Products once sold cannot be returned.' ?>
|
||||
</textarea>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($sales['status']) || $sales['status'] !== 'Paid') : ?>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
productarray = [];
|
||||
$(document).ready(function() {
|
||||
// Event listener for vehicle selection change
|
||||
$('.vendor-select').change(function() {
|
||||
var vendorId = $(this).val();
|
||||
|
||||
if (vendorId !== '') {
|
||||
// Find the selected vehicle
|
||||
var selectedVehicle = vendors.find(function(vendor) {
|
||||
return vendor.vendor_id == vendorId;
|
||||
});
|
||||
|
||||
// Extract makeId from the selected vehicle
|
||||
|
||||
|
||||
// Make sure makeId exists
|
||||
if (vendorId !== undefined) {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getVendorProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
|
||||
vendor_id: vendorId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
productarray = response.product;
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Make ID not found for the selected vehicle');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
<?php
|
||||
$product_json = json_encode($product);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
function validateProductAdded() {
|
||||
var rowCount = $('#itemTable tbody tr').length;
|
||||
if (rowCount < 1) {
|
||||
toastr.warning("Please add at least one product.");
|
||||
// alert("Please add at least one product.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Event listener for form submission
|
||||
$('form').submit(function() {
|
||||
return validateProductAdded();
|
||||
});
|
||||
|
||||
var products = <?php echo $product_json; ?>;
|
||||
|
||||
// Function to calculate amount based on rate and quantity
|
||||
function calculateAmount(row) {
|
||||
var rate = $(row).find('.item-rate').val();
|
||||
var quantity = $(row).find('.item-quantity').val();
|
||||
var amount = rate * quantity;
|
||||
$(row).find('.item-amount').val(amount);
|
||||
|
||||
// Retrieve CGST and SGST values from the database for the selected product
|
||||
var productId = $(row).find('select[name="item_details[]"]').val();
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var sgst = parseFloat(product.sgst);
|
||||
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + sgst;
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
}
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(0);
|
||||
|
||||
// Find product details from JSON
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
calculateAmount($(this).closest('tr'));
|
||||
});
|
||||
|
||||
// Event listener for quantity change
|
||||
$(document).on('input', '.item-quantity', function() {
|
||||
calculateAmount($(this).closest('tr'));
|
||||
updateCalculations(); // Added for updating calculations when quantity changes
|
||||
});
|
||||
|
||||
// Function to calculate subtotal
|
||||
function calculateSubtotal() {
|
||||
var subtotal = 0;
|
||||
$('.item-amount').each(function() {
|
||||
subtotal += parseFloat($(this).val()) || 0;
|
||||
});
|
||||
return subtotal;
|
||||
}
|
||||
|
||||
// Function to calculate total tax
|
||||
function calculateTax() {
|
||||
|
||||
var tax = 0;
|
||||
$('.item-tax').each(function() {
|
||||
var taxPercentage = parseFloat($(this).val()) || 0;
|
||||
var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
|
||||
var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value
|
||||
tax += taxValue;
|
||||
});
|
||||
return tax;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to calculate total discount
|
||||
function calculateDiscount() {
|
||||
var totalDiscount = 0;
|
||||
$('.item-discount-amount').each(function(index, element) {
|
||||
var discountAmount = parseFloat($(element).val()) || 0;
|
||||
var discountType = $(element).closest('tr').find('.item-discount-type').val();
|
||||
if (discountType === '%') {
|
||||
var rate = $(element).closest('tr').find('.item-rate').val();
|
||||
var quantity = $(element).closest('tr').find('.item-quantity').val();
|
||||
var amount = rate * quantity;
|
||||
discountAmount = amount * discountAmount / 100;
|
||||
}
|
||||
totalDiscount += discountAmount;
|
||||
});
|
||||
return totalDiscount;
|
||||
}
|
||||
|
||||
// Function to calculate total
|
||||
function calculateTotal() {
|
||||
var subtotal = calculateSubtotal();
|
||||
var tax = calculateTax();
|
||||
var discount = calculateDiscount();
|
||||
var total = subtotal + tax - discount;
|
||||
// return total;
|
||||
return Math.round(total);
|
||||
}
|
||||
|
||||
// Update subtotal, tax, and total
|
||||
function updateCalculations() {
|
||||
$('#subtotal').val(calculateSubtotal().toFixed(2));
|
||||
$('#invoicetax').val(calculateTax().toFixed(2));
|
||||
$('#discount').val(calculateDiscount().toFixed(2));
|
||||
$('#grandtotal').val(calculateTotal().toFixed(2));
|
||||
}
|
||||
|
||||
// Event listener for discount change
|
||||
$(document).on('input', '.item-discount-amount, .item-discount-type', function() {
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
// Calculate initial values on page load
|
||||
updateCalculations();
|
||||
|
||||
// Event listener for "Add More Item" button
|
||||
$('#addItem').click(function() {
|
||||
console.log(productarray);
|
||||
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
|
||||
|
||||
for (var i = 0; i < productarray.length; i++)
|
||||
{
|
||||
var product = productarray[i];
|
||||
newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
|
||||
}
|
||||
|
||||
newRow += '</select></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
|
||||
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
|
||||
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
||||
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
|
||||
'<td hidden><input type="hidden"></td>' +
|
||||
'<td><center><i class="fa fa-trash remove-item"></i></center></td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
$('#itemTable tbody').append(newRow);
|
||||
initializeSelect2();
|
||||
|
||||
|
||||
});
|
||||
|
||||
// Event listener for removing item
|
||||
$(document).on('click', '.remove-item', function() {
|
||||
$(this).closest('tr').remove();
|
||||
updateCalculations(); // Added for updating calculations when an item is removed
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script>
|
||||
// Event listener for removing item
|
||||
// Event listener for removing item
|
||||
$(document).on('click', '.remove-item', function() {
|
||||
var purchase_order_child_id = $(this).closest('tr').find('input[name="purchase_order_child_id[]"]').val();
|
||||
|
||||
// AJAX request to delete the sales order product
|
||||
$.ajax({
|
||||
url: '<?php echo base_url()."delete_purchase_product"?>',
|
||||
method: 'POST',
|
||||
data: { purchase_order_child_id: purchase_order_child_id },
|
||||
success: function(response) {
|
||||
// Check if the deletion was successful
|
||||
if (response.success) {
|
||||
// If successful, remove the row from the table
|
||||
$(this).closest('tr').remove();
|
||||
updateCalculations(); // Update calculations after removing the row
|
||||
} else {
|
||||
// If not successful, display an error message
|
||||
// alert('Error occurred while deleting the item.');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while deleting the item:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).ready(function() {
|
||||
// Event listener for customer selection change
|
||||
$('.vehicle-select').change(function() {
|
||||
|
||||
var vehicleId = $(this).val();
|
||||
if (vehicleId !== '') {
|
||||
// Find the selected client in the client data
|
||||
var selectedClient = vehicles.find(function(vehicle) {
|
||||
return vehicle.vehicle_id == vehicleId;
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('input[name="client_id"]').val(selectedClient.client_name);
|
||||
$('input[name="billing_address"]').val(selectedClient.address);
|
||||
$('input[name="billing_address"]').val(selectedClient.address);
|
||||
$('input[name="city"]').val(selectedClient.city);
|
||||
$('input[name="state"]').val(selectedClient.state);
|
||||
$('input[name="country"]').val(selectedClient.country);
|
||||
$('input[name="mobile_no"]').val(selectedClient.mobile_no);
|
||||
$('input[name="postalcode"]').val(selectedClient.postal_code);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Event listener for customer selection change
|
||||
$('.cleint-select').change(function() {
|
||||
|
||||
var clientId = $(this).val();
|
||||
// console.log(vehicleId);
|
||||
if (clientId !== '') {
|
||||
// Find the selected client in the client data
|
||||
var selectedClients = clients.find(function(client) {
|
||||
return client.client_id == clientId;
|
||||
});
|
||||
|
||||
// Populate the billing address, city, state, country, and postal code fields
|
||||
|
||||
|
||||
$('input[id="clientMobile"]').val(selectedClients.mobile_no);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Define the clients array and populate it with data
|
||||
var vendors = <?php echo json_encode($vendor); ?>;
|
||||
|
||||
</script>
|
||||
<script>
|
||||
function onlyNumbers(event){
|
||||
var charcode;
|
||||
charcode = event.which || event.keyCode;
|
||||
if(charcode>= 48 && charcode <= 57)return true;
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// Initialize select2
|
||||
$(".SelExample").select2();
|
||||
});
|
||||
function initializeSelect2() {
|
||||
$('.SelExample').select2({
|
||||
width: '249px' // Adjust width as needed
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
// AJAX request to save client
|
||||
$('#saveVehcileBtn').click(function() {
|
||||
|
||||
var formType = $('#formType').val();
|
||||
console.log(formType);
|
||||
|
||||
var reg_no = $('#reg_no').val();
|
||||
var model = $('#model').val();
|
||||
var make = $('#make').val();
|
||||
|
||||
var clientName = $('#clientName').val();
|
||||
var clientMobile = $('#clientMobile').val();
|
||||
|
||||
var createclientName = $('#create-clientName').val();
|
||||
var createclientMobile = $('#create-clientMobile').val();
|
||||
var createclientType = $('#create-clientType').val();
|
||||
|
||||
if (formType == 'select')
|
||||
{
|
||||
var ifStatementCondition = "clientName !== '' && clientMobile !== '' && reg_no !== '' && model !== '' && make !== ''";
|
||||
} else {
|
||||
var ifStatementCondition = "createclientName !== '' && createclientMobile !== '' && createclientType !== '' && reg_no !== '' && model !== '' && make !== ''";
|
||||
}
|
||||
|
||||
console.log(ifStatementCondition);
|
||||
|
||||
if( eval(ifStatementCondition) ){
|
||||
|
||||
// Send AJAX request to save the client
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_vehicle'?>', // URL to your save_client method
|
||||
method: 'POST',
|
||||
data: {
|
||||
client_id: clientName,
|
||||
mobile_no: clientMobile,
|
||||
reg_no:reg_no,
|
||||
model:model,
|
||||
make:make,
|
||||
createclientName:createclientName,
|
||||
createclientMobile:createclientMobile,
|
||||
createclientType:createclientType,
|
||||
formType:formType,
|
||||
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$('#addVehicleModal').modal('hide');
|
||||
toastr.success("Vehicle saved successfully!");
|
||||
window.location.reload();
|
||||
|
||||
} else {
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving vehicle:', error);
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
}
|
||||
});
|
||||
|
||||
}else{
|
||||
toastr.warning("Please Fill All Data");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<script>
|
||||
$(".SelExample").select2();
|
||||
|
||||
// Event listener for change in make select dropdown
|
||||
$("#make").on('change', function() {
|
||||
var selected_makes = $(this).val(); // Get an array of selected make IDs
|
||||
// AJAX request to fetch models based on selected make IDs
|
||||
$.ajax({
|
||||
url: '<?= base_url("fetch_models") ?>', // URL to your controller method for fetching models
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { selected_makes: [selected_makes] },
|
||||
success: function(response) {
|
||||
// Clear existing options in model select dropdown
|
||||
$("#model").empty();
|
||||
$("#model").append('<option value=""> Select a Model </option>');
|
||||
// Populate model select dropdown with fetched models
|
||||
$.each(response, function(index, model) {
|
||||
$("#model").append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
|
||||
});
|
||||
|
||||
// Refresh select2 to reflect changes
|
||||
$("#model").trigger('change');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(error); // Log any errors to the console
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('reg_no').addEventListener('input', function(event) {
|
||||
var inputText = event.target.value;
|
||||
event.target.value = inputText.toUpperCase();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click', '#createClient', function() {
|
||||
$('.create').show();
|
||||
$('.select').hide();
|
||||
$('#formType').val('create');
|
||||
|
||||
$('#clientName').val('');
|
||||
$('#clientMobile').val('');
|
||||
|
||||
|
||||
});
|
||||
$(document).on('click', '#selectClient', function() {
|
||||
$('.select').show();
|
||||
$('.create').hide();
|
||||
$('#formType').val('select');
|
||||
|
||||
$('#create-clientName').val('');
|
||||
$('#create-clientMobile').val('');
|
||||
$('#create-clientType').val('');
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.select2-container .select2-selection--multiple .select2-selection__choice{
|
||||
padding: 5px 7px 5px 0 !important;
|
||||
color: #000000;
|
||||
|
||||
}
|
||||
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
||||
color:#ffffff;
|
||||
background-color: #526dee;
|
||||
}
|
||||
.select2-container--default .select2-results__option{
|
||||
border-bottom: 1px solid #dddddd;
|
||||
}
|
||||
.select2-container--default .select2-results__option[aria-selected=true]{
|
||||
color: #000000;
|
||||
background-color: #3efba4;
|
||||
font-weight: 500;
|
||||
border-bottom: 1px solid #747474;
|
||||
}
|
||||
</style>
|
||||
@ -42,13 +42,15 @@
|
||||
<?php foreach ($reorder as $value) :
|
||||
?>
|
||||
<tr>
|
||||
<td hidden><?= $value['product_id']; ?></td>
|
||||
<td><?= $value['product_name']; ?></td>
|
||||
<td><?= number_format($value['unit_price']); ?></td>
|
||||
<td><?= $value['qty_stock']; ?></td>
|
||||
<td><?= $value['purchase_order_level']; ?></td>
|
||||
<td><?= $value['reorder_level']; ?></td>
|
||||
|
||||
|
||||
<td>
|
||||
<a href="<?= "rise_order/" . $value['product_id']; ?>" class="edit-button"><i class="ri-arrow-up-circle-fill"></i>Rise</a>
|
||||
</td>
|
||||
|
||||
|
||||
<!-- Call the model method -->
|
||||
|
||||
129
app/Views/return_list.php
Normal file
129
app/Views/return_list.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php include('layout/header.php'); ?>
|
||||
<style>
|
||||
.dataTables_wrapper button{
|
||||
background: #f1f5f7;
|
||||
color: #343a40;
|
||||
border-width: 0;
|
||||
}
|
||||
.dataTables_wrapper .dt-buttons{
|
||||
float:left;
|
||||
}
|
||||
.cancelled-status {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.created-status {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.paid-status {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box page-title-box-alt">
|
||||
<h4 class="page-title">Return Order List </h4>
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class=""> <a href="<?= base_url() . "return_order_index"; ?>" class="btn btn-primary waves-effect"> <i class="ri-add-line"></i></a>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<!-- <h4 class="header-title">Business List</h4> -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<table id="datatable-buttons3" class="table table-striped dt-responsive nowrap w-100"
|
||||
style="width:100% !important;">
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
<th>Order Number</th>
|
||||
<th>Vendor Name</th>
|
||||
<th>Order Date</th>
|
||||
<th>Contact Person Details</th>
|
||||
<!-- <th>Contact Person Mobile</th> -->
|
||||
<th>Quantity</th>
|
||||
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
|
||||
|
||||
<!-- Call the model method -->
|
||||
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- end table-responsive-->
|
||||
|
||||
</div>
|
||||
</div> <!-- end card -->
|
||||
</div> <!-- end col -->
|
||||
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#datatable-buttons3').DataTable({
|
||||
"order": [[2, 'desc']], // Set initial sorting to descending on the first column
|
||||
"dom": 'Bfrtip', // Show export buttons
|
||||
"buttons": [ {
|
||||
extend: 'pdfHtml5',
|
||||
title: 'Transaction', // Set your custom PDF title here
|
||||
text: 'PDF',
|
||||
customize: function(doc) {
|
||||
// You can further customize the PDF here if needed
|
||||
// doc.content[1].table.body.forEach(function(row) {
|
||||
// row.splice(0, 1); // Remove the first column (ID column)
|
||||
// });
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'print',
|
||||
title: 'Transaction', // Set your custom print title here
|
||||
text: 'Print',
|
||||
customize: function(win) {
|
||||
// You can further customize the print output here if needed
|
||||
// $(win.document.body).find('table').find('th:first-child, td:first-child').remove();
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'copy',
|
||||
text: 'Copy', // Set the title for the Copy button
|
||||
titleAttr: 'Copy', // Set the tooltip for the Copy button
|
||||
exportOptions: {
|
||||
// columns: ':not(:first-child)' // Exclude the first column (ID column)
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'csv',
|
||||
text: 'CSV', // Set the title for the CSV button
|
||||
title: 'Transaction', // Set your custom print title here
|
||||
exportOptions: {
|
||||
// columns: ':not(:first-child)' // Exclude the first column (ID column)
|
||||
}
|
||||
}], // Enable export options
|
||||
"language": {
|
||||
"search": "Search: " // Customize search label
|
||||
},
|
||||
"ordering": false
|
||||
});
|
||||
});
|
||||
</script>
|
||||
555
app/Views/return_order_form.php
Normal file
555
app/Views/return_order_form.php
Normal file
@ -0,0 +1,555 @@
|
||||
<?php include('layout/header.php'); ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box page-title-box-alt">
|
||||
<h4 class="page-title"><?php echo $page_name?></h4>
|
||||
<div class="page-title-right">
|
||||
<a href="<?= base_url() . "purchase_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
||||
<ol class="breadcrumb m-0">
|
||||
|
||||
</li>
|
||||
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
|
||||
<li class="breadcrumb-item active">Datatables</li> -->
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"></h4>
|
||||
<form action="<?= base_url() . "add_purchase"; ?>" method="post">
|
||||
<input type="hidden" id="purchase_order_id" name="purchase_order_id" value="<?= isset($purchase['purchase_order_id']) ? $purchase['purchase_order_id'] : '' ?>"readonly>
|
||||
<h4 class="header-title">Purchase Details :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="make" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<select class="form-control vendor-select SelExample" name="vendor_id" id="vendor_id" <?php echo in_array($vendor_id, array_column($vendor, 'vendor_id')) ? 'disabled' : ''; ?>>
|
||||
<option value="0">Select Vendor</option>
|
||||
<?php foreach ($vendor as $item): ?>
|
||||
<option value="<?= $item['vendor_id'] ?>" <?= isset($item['vendor_id']) && $vendor_id == $item['vendor_id'] ? 'selected' : '' ?>>
|
||||
<?= $item['vendor_name'] ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_name" class="col-form-label">Contact Person Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_name" id="contact_person_name" placeholder="Contact Person Name.."value="<?= isset($purchase['contact_person_name']) ? $purchase['contact_person_name'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_mobile" class="col-form-label">Contact Person Mobile<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_mobile" id="contact_person_mobile" placeholder="Contact Person Mobile" value="<?= isset($purchase['contact_person_mobile']) ? $purchase['contact_person_mobile'] : '' ?>"maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Order Date</label>
|
||||
<input type="date" class="form-control" name="order_date" id="order_date" value="<?= empty($purchase['order_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['order_date'])) ?>" readonly>
|
||||
</div>
|
||||
<?php if (!empty($purchase["status"])): ?>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Return Date</label>
|
||||
<input type="date" class="form-control" name="return_date" id="return_date" value="<?= empty($purchase['return_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['return_date'])) ?>" >
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>
|
||||
<?php if (isset($purchase['status']) && $purchase['status'] !== ''): ?>
|
||||
(<?= $purchase['status'] ?>)
|
||||
<?php endif; ?></label>
|
||||
<select class="form-control status-select" name="purchase_status" required data-toggle="select2">
|
||||
<?php if (isset($purchase['status'])): ?>
|
||||
<?php if ($purchase['status'] === 'Cancel'): ?>
|
||||
<option value="">Select Status</option>
|
||||
<option value="Released" <?= $purchase['status'] === 'Released' ? 'selected' : '' ?>>Released</option>
|
||||
<?php else: ?>
|
||||
<option value="">Select Status</option>
|
||||
<option value="Released" <?= $purchase['status'] === 'Released' ? 'selected' : '' ?>>Released</option>
|
||||
<option value="Cancel" <?= $purchase['status'] === 'Cancel' ? 'selected' : '' ?>>Cancel</option>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<option value="Draft" selected>Draft</option>
|
||||
<!-- <option value="Paid">Paid</option> -->
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<h4 class="header-title">Billing Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="billing_address" class="col-form-label">Billing Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_address" id="billing_address" placeholder="Billing Addresss"value="<?= isset($business['address']) ? $business['address'] : (isset($purchase['billing_address']) ? $purchase['billing_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="billing_state" class="col-form-label">Billing State</label>
|
||||
<input type="text" class="form-control" name="billing_state" id="billing_state" placeholder="Billing State"value="<?= isset($business['state']) ? $business['state'] : (isset($purchase['billing_state']) ? $purchase['billing_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing City" class="col-form-label">Billing City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_city" id="billing_city" placeholder="Billing City"value="<?= isset($business['city']) ? $business['city'] : (isset($purchase['billing_city']) ? $purchase['billing_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing Postal Code" class="col-form-label">Billing Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_postal_code" id="billing_postal_code" placeholder="Billing Pin Code"value="<?= isset($business['postal_code']) ? $business['postal_code'] : (isset($purchase['billing_postal_code']) ? $purchase['billing_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
|
||||
</div><br>
|
||||
<h4 class="header-title">Shipping Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="shipping_address" class="col-form-label">Shipping Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_address" id="shipping_address" placeholder="Shipping Addresss"value="<?= isset($branch['address']) ? $branch['address'] : (isset($purchase['shipping_address']) ? $purchase['shipping_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="shipping_state" class="col-form-label">Shipping State</label>
|
||||
<input type="text" class="form-control" name="shipping_state" id="shipping_state" placeholder="Shipping State"value="<?= isset($branch['state']) ? $branch['state'] : (isset($purchase['shipping_state']) ? $purchase['shipping_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping City" class="col-form-label">Shipping City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_city" id="shipping_city" placeholder="Shipping City"value="<?= isset($branch['city']) ? $branch['city'] : (isset($purchase['shipping_city']) ? $purchase['shipping_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping Postal Code" class="col-form-label">Shipping Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_postal_code" id="shipping_postal_code" placeholder="Shipping Pin Code"value="<?= isset($branch['postal_code']) ? $branch['postal_code'] : (isset($purchase['shipping_postal_code']) ? $purchase['shipping_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
</div><br>
|
||||
|
||||
<div class="form-row" id="itemTableContainer">
|
||||
<div class="form-group col-md-12">
|
||||
<h4>Item Details</h4>
|
||||
<br />
|
||||
|
||||
<table class="table table-bordered" id="itemTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Item Details</th>
|
||||
<th>Qty</th>
|
||||
<?php if (!empty($purchase["status"])): ?>
|
||||
<th>Returned</th>
|
||||
<?php endif; ?>
|
||||
<th hidden></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<!-- Dynamically add rows for item details -->
|
||||
<?php if (isset($purchase_product) && !empty($purchase_product)) : ?>
|
||||
<?php foreach ($purchase_product as $purchasechild) :
|
||||
if ($purchasechild['isactive'] == 1) : ?>
|
||||
<tr>
|
||||
<td style="width:10%;">
|
||||
|
||||
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
|
||||
<option value="">Select a Product</option>
|
||||
<?php foreach ($product as $value) : ?>
|
||||
<?php if ((int)$value["isactive"] === 1) : ?>
|
||||
<option value="<?= $value["product_id"] ?>" <?= isset($purchasechild['product_id']) && $purchasechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>>
|
||||
<?= $value["product_name"]; ?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<td style="width:5%;">
|
||||
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:2%;">
|
||||
<input type="checkbox" class="form-control-check-input" name="selected_items[]" value="<?= ($purchasechild['is_selected']) ? '0' : '1' ?>" <?php echo ($purchasechild['is_selected']) ? 'checked' : '1'; ?>>
|
||||
</td>
|
||||
<td style="width:2%;">
|
||||
<input type="checkbox" class="form-control-check-input" name="selected_items[]" value="<?= ($purchasechild['is_selected']) ? '0' : '1' ?>" <?php echo ($purchasechild['is_selected']) ? 'checked' : '1'; ?>>
|
||||
</td>
|
||||
<td style="width:2%;">
|
||||
<input type="checkbox" class="form-control-check-input" name="selected_items[]" value="<?= ($return['is_selected']) ? '0' : '1' ?>" <?php echo ($return['is_selected']) ? 'checked' : '1'; ?>>
|
||||
</td>
|
||||
|
||||
<td hidden><input type="hidden" value="<?= isset($purchasechild['purchase_order_child_id']) ? $purchasechild['purchase_order_child_id'] : '' ?>"name="purchase_order_child_id[]"></td>
|
||||
<td style="width:5%;">
|
||||
<center><i class="fa fa-trash remove-item"></i></center>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<!-- You can add more rows as needed using JavaScript -->
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if (empty($purchase["status"])): ?>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<!-- Show the "Add More Item" button only if invoice_type is not 1 -->
|
||||
<a class="btn" id="addItem">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="header-title">Terms & Condition :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-12">
|
||||
|
||||
|
||||
<label for="inputPassword4" class="col-form-label">Terms & Condition</label>
|
||||
<textarea class="form-control" name="terms_condition" placeholder="Terms & Condition" >
|
||||
<?= isset($sales['terms_condition']) ? $sales['terms_condition'] : 'Please check the products properly before purchase. Products once sold cannot be returned.' ?>
|
||||
</textarea>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($purchase['status']) || $purchase['status'] !== 'Released') : ?>
|
||||
<button type="submit" id="editaddbutton"class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
productarray = [];
|
||||
$(document).ready(function() {
|
||||
// Function to fetch products based on vendor ID
|
||||
function fetchVendorProducts(vendorId) {
|
||||
if (vendorId !== '') {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getVendorProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
vendor_id: vendorId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
// Assuming response contains product data
|
||||
// You can handle product data as per your requirements
|
||||
// For example, updating UI or populating a dropdown with products
|
||||
// Here, I'm just logging the product array to the console
|
||||
productarray = response.product;
|
||||
console.log(productarray);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Vendor ID not found');
|
||||
}
|
||||
}
|
||||
|
||||
// Event listener for vendor selection change
|
||||
$('.vendor-select').change(function() {
|
||||
var vendorId = $(this).val();
|
||||
fetchVendorProducts(vendorId);
|
||||
});
|
||||
|
||||
// Edit scenario: Populate products based on stored vendor ID
|
||||
var storedVendorId = "<?php echo isset($purchase['vendor_id']) ? $purchase['vendor_id'] : ''; ?>";
|
||||
if (storedVendorId !== '') {
|
||||
// Trigger change event to fetch products based on stored vendor ID
|
||||
$('#vendor_id').val(storedVendorId).change();
|
||||
}
|
||||
});
|
||||
|
||||
<?php
|
||||
$product_json = json_encode($product);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
function validateProductAdded() {
|
||||
var rowCount = $('#itemTable tbody tr').length;
|
||||
if (rowCount < 1) {
|
||||
toastr.warning("Please add at least one product.");
|
||||
// alert("Please add at least one product.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Event listener for form submission
|
||||
$('form').submit(function() {
|
||||
return validateProductAdded();
|
||||
});
|
||||
|
||||
var products = <?php echo $product_json; ?>;
|
||||
|
||||
// Function to calculate amount based on rate and quantity
|
||||
function calculateAmount(row) {
|
||||
var rate = $(row).find('.item-rate').val();
|
||||
var quantity = $(row).find('.item-quantity').val();
|
||||
var amount = rate * quantity;
|
||||
$(row).find('.item-amount').val(amount);
|
||||
|
||||
// Retrieve CGST and SGST values from the database for the selected product
|
||||
var productId = $(row).find('select[name="item_details[]"]').val();
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var sgst = parseFloat(product.sgst);
|
||||
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + sgst;
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
}
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
||||
|
||||
// Find product details from JSON
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
calculateAmount($(this).closest('tr'));
|
||||
});
|
||||
|
||||
// Event listener for quantity change
|
||||
$(document).on('input', '.item-quantity', function() {
|
||||
calculateAmount($(this).closest('tr'));
|
||||
updateCalculations(); // Added for updating calculations when quantity changes
|
||||
});
|
||||
|
||||
// Function to calculate subtotal
|
||||
function calculateSubtotal() {
|
||||
var subtotal = 0;
|
||||
$('.item-amount').each(function() {
|
||||
subtotal += parseFloat($(this).val()) || 0;
|
||||
});
|
||||
return subtotal;
|
||||
}
|
||||
|
||||
// Function to calculate total tax
|
||||
function calculateTax() {
|
||||
|
||||
var tax = 0;
|
||||
$('.item-tax').each(function() {
|
||||
var taxPercentage = parseFloat($(this).val()) || 0;
|
||||
var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
|
||||
var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value
|
||||
tax += taxValue;
|
||||
});
|
||||
return tax;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to calculate total discount
|
||||
function calculateDiscount() {
|
||||
var totalDiscount = 0;
|
||||
$('.item-discount-amount').each(function(index, element) {
|
||||
var discountAmount = parseFloat($(element).val()) || 0;
|
||||
var discountType = $(element).closest('tr').find('.item-discount-type').val();
|
||||
if (discountType === '%') {
|
||||
var rate = $(element).closest('tr').find('.item-rate').val();
|
||||
var quantity = $(element).closest('tr').find('.item-quantity').val();
|
||||
var amount = rate * quantity;
|
||||
discountAmount = amount * discountAmount / 100;
|
||||
}
|
||||
totalDiscount += discountAmount;
|
||||
});
|
||||
return totalDiscount;
|
||||
}
|
||||
|
||||
// Function to calculate total
|
||||
function calculateTotal() {
|
||||
var subtotal = calculateSubtotal();
|
||||
var tax = calculateTax();
|
||||
var discount = calculateDiscount();
|
||||
var total = subtotal + tax - discount;
|
||||
// return total;
|
||||
return Math.round(total);
|
||||
}
|
||||
|
||||
// Update subtotal, tax, and total
|
||||
function updateCalculations() {
|
||||
$('#subtotal').val(calculateSubtotal().toFixed(2));
|
||||
$('#invoicetax').val(calculateTax().toFixed(2));
|
||||
$('#discount').val(calculateDiscount().toFixed(2));
|
||||
$('#grandtotal').val(calculateTotal().toFixed(2));
|
||||
}
|
||||
|
||||
// Event listener for discount change
|
||||
$(document).on('input', '.item-discount-amount, .item-discount-type', function() {
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
// Calculate initial values on page load
|
||||
updateCalculations();
|
||||
|
||||
// Event listener for "Add More Item" button
|
||||
$('#addItem').click(function() {
|
||||
console.log(productarray);
|
||||
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
|
||||
|
||||
for (var i = 0; i < productarray.length; i++)
|
||||
{
|
||||
var product = productarray[i];
|
||||
newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
|
||||
}
|
||||
|
||||
newRow += '</select></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
|
||||
|
||||
|
||||
'<td><center><i class="fa fa-trash remove-item"></i></center></td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
$('#itemTable tbody').append(newRow);
|
||||
initializeSelect2();
|
||||
|
||||
|
||||
});
|
||||
|
||||
// Event listener for removing item
|
||||
$(document).on('click', '.remove-item', function() {
|
||||
$(this).closest('tr').remove();
|
||||
updateCalculations(); // Added for updating calculations when an item is removed
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script>
|
||||
// Validate form before submission
|
||||
$('form').submit(function() {
|
||||
var status = $('select[name="purchase_status"]').val();
|
||||
if (status === "") {
|
||||
alert("Please select a status.");
|
||||
return false; // Prevent form submission
|
||||
}
|
||||
// If all validations pass, allow form submission
|
||||
return true;
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Event listener for removing item
|
||||
// Event listener for removing item
|
||||
$(document).on('click', '.remove-item', function() {
|
||||
var purchase_order_child_id = $(this).closest('tr').find('input[name="purchase_order_child_id[]"]').val();
|
||||
|
||||
// AJAX request to delete the sales order product
|
||||
$.ajax({
|
||||
url: '<?php echo base_url()."delete_purchase_product"?>',
|
||||
method: 'POST',
|
||||
data: { purchase_order_child_id: purchase_order_child_id },
|
||||
success: function(response) {
|
||||
// Check if the deletion was successful
|
||||
if (response.success) {
|
||||
// If successful, remove the row from the table
|
||||
$(this).closest('tr').remove();
|
||||
updateCalculations(); // Update calculations after removing the row
|
||||
} else {
|
||||
// If not successful, display an error message
|
||||
// alert('Error occurred while deleting the item.');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while deleting the item:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).ready(function() {
|
||||
// Event listener for customer selection change
|
||||
$('.vendor-select').change(function() {
|
||||
console.log(vendors);
|
||||
var vendorId = $(this).val();
|
||||
if (vendorId !== '') {
|
||||
// Find the selected client in the client data
|
||||
var selctedVendor = vendors.find(function(vendor) {
|
||||
return vendor.vendor_id == vendorId;
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('input[name="contact_person_name"]').val(selctedVendor.contact_person_name1);
|
||||
$('input[name="contact_person_mobile"]').val(selctedVendor.contact_person_mobile1);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Define the clients array and populate it with data
|
||||
var vendors = <?php echo json_encode($vendor); ?>;
|
||||
|
||||
</script>
|
||||
<script>
|
||||
function onlyNumbers(event){
|
||||
var charcode;
|
||||
charcode = event.which || event.keyCode;
|
||||
if(charcode>= 48 && charcode <= 57)return true;
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// Initialize select2
|
||||
$(".SelExample").select2();
|
||||
});
|
||||
function initializeSelect2() {
|
||||
$('.SelExample').select2({
|
||||
width: '249px' // Adjust width as needed
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
||||
color:#ffffff;
|
||||
background: #526dee!important;
|
||||
}
|
||||
.select2-container .select2-selection--single{
|
||||
height: 36px;
|
||||
border:1px solid #ced4da;
|
||||
}
|
||||
.select2-container--default .select2-selection--single .select2-selection__rendered{
|
||||
line-height: 36px;
|
||||
}
|
||||
.select2-container--default .select2-selection--single .select2-selection__arrow{
|
||||
top:4px;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
// Assuming you have an edit button with an ID 'editButton'
|
||||
$('#editaddbutton').click(function() {
|
||||
// Enable the vendor dropdown
|
||||
$('#vendor_id').prop('disabled', false);
|
||||
});
|
||||
</script>
|
||||
155
app/Views/return_order_liist.php
Normal file
155
app/Views/return_order_liist.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php include('layout/header.php'); ?>
|
||||
<style>
|
||||
.dataTables_wrapper button{
|
||||
background: #f1f5f7;
|
||||
color: #343a40;
|
||||
border-width: 0;
|
||||
}
|
||||
.dataTables_wrapper .dt-buttons{
|
||||
float:left;
|
||||
}
|
||||
.cancelled-status {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.created-status {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.paid-status {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box page-title-box-alt">
|
||||
<h4 class="page-title">Return Order List </h4>
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<!-- <li class=""> <a href="<?= base_url() . "new_return/0"; ?>" class="btn btn-primary waves-effect"> <i class="ri-add-line"></i></a>
|
||||
</li> -->
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<!-- <h4 class="header-title">Business List</h4> -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<table id="datatable-buttons3" class="table table-striped dt-responsive nowrap w-100"
|
||||
style="width:100% !important;">
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
<th>Order Number</th>
|
||||
<th>Vendor Name</th>
|
||||
<th>Order Date</th>
|
||||
<th>Contact Person Details</th>
|
||||
<!-- <th>Contact Person Mobile</th> -->
|
||||
<th>Quantity</th>
|
||||
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php foreach ($purchase as $value) :
|
||||
if ($value['status'] =='Released') : ?>
|
||||
<tr>
|
||||
<td><?= $value['order_number']; ?></td>
|
||||
<td><?= $value['vendor_name']; ?></td>
|
||||
<td><?= date('j F Y', strtotime($value['order_date'])); ?></td>
|
||||
<td><?= $value['contact_person_name']; ?><br>
|
||||
<?= $value['contact_person_mobile']; ?>
|
||||
<td><?= $value['product_count']; ?></td>
|
||||
<td class="<?php
|
||||
if ($value['status'] == 'Cancel') {
|
||||
echo 'cancelled-status';
|
||||
} elseif ($value['status'] == 'Draft') {
|
||||
echo 'created-status';
|
||||
} elseif ($value['status'] == 'Released') {
|
||||
echo 'paid-status';
|
||||
}
|
||||
?>">
|
||||
<?= $value['status']; ?>
|
||||
</td>
|
||||
|
||||
<!-- Call the model method -->
|
||||
|
||||
<td>
|
||||
<a href="<?= "new_return/" . $value['purchase_order_id']; ?>" class="edit-button" title="Return"><i class="ri-arrow-left-circle-fill" style="font-size: 20px;"></i></a>
|
||||
<a href="<?= "delete_purchase/" . $value['purchase_order_id']; ?>" class="delete-button" title="Delete"><i class="ri-delete-bin-line" style="font-size: 20px;"></i></a>
|
||||
<a href="<?= "download_purchase_invoice/" . $value['purchase_order_id']; ?>" class="edit-button" title="Download"><i class="ri-download-2-fill" style="font-size: 20px;"></i></a>
|
||||
</td>
|
||||
|
||||
<?php endif?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- end table-responsive-->
|
||||
|
||||
</div>
|
||||
</div> <!-- end card -->
|
||||
</div> <!-- end col -->
|
||||
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#datatable-buttons3').DataTable({
|
||||
"order": [[2, 'desc']], // Set initial sorting to descending on the first column
|
||||
"dom": 'Bfrtip', // Show export buttons
|
||||
"buttons": [ {
|
||||
extend: 'pdfHtml5',
|
||||
title: 'Transaction', // Set your custom PDF title here
|
||||
text: 'PDF',
|
||||
customize: function(doc) {
|
||||
// You can further customize the PDF here if needed
|
||||
// doc.content[1].table.body.forEach(function(row) {
|
||||
// row.splice(0, 1); // Remove the first column (ID column)
|
||||
// });
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'print',
|
||||
title: 'Transaction', // Set your custom print title here
|
||||
text: 'Print',
|
||||
customize: function(win) {
|
||||
// You can further customize the print output here if needed
|
||||
// $(win.document.body).find('table').find('th:first-child, td:first-child').remove();
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'copy',
|
||||
text: 'Copy', // Set the title for the Copy button
|
||||
titleAttr: 'Copy', // Set the tooltip for the Copy button
|
||||
exportOptions: {
|
||||
// columns: ':not(:first-child)' // Exclude the first column (ID column)
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'csv',
|
||||
text: 'CSV', // Set the title for the CSV button
|
||||
title: 'Transaction', // Set your custom print title here
|
||||
exportOptions: {
|
||||
// columns: ':not(:first-child)' // Exclude the first column (ID column)
|
||||
}
|
||||
}], // Enable export options
|
||||
"language": {
|
||||
"search": "Search: " // Customize search label
|
||||
},
|
||||
"ordering": false
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@ -8,6 +8,18 @@
|
||||
.dataTables_wrapper .dt-buttons{
|
||||
float:left;
|
||||
}
|
||||
.cancelled-status {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.created-status {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.paid-status {
|
||||
color: green;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
@ -42,10 +54,9 @@
|
||||
<th>Order Number</th>
|
||||
<th>Reg No</th>
|
||||
<th>Client Name</th>
|
||||
<th>Client Mobile</th>
|
||||
|
||||
<th>Quantity</th>
|
||||
<th>Subtotal</th>
|
||||
<th>Tax</th>
|
||||
|
||||
<th>Total</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
@ -64,19 +75,28 @@
|
||||
<td><?= $value['order_number']; ?></td>
|
||||
<td><?= $value['reg_no']; ?></td>
|
||||
<td><?= $value['client_name']; ?></td>
|
||||
<td><?= $value['mobile_no']; ?></td>
|
||||
|
||||
<td><?= $value['product_count']; ?></td>
|
||||
<td><?= $value['subtotal']; ?></td>
|
||||
<td><?= $value['tax']; ?></td>
|
||||
|
||||
<td><?= $value['total']; ?></td>
|
||||
<td><?= $value['status']; ?></td>
|
||||
<td>
|
||||
<a href="<?= "new_sale/" . $value['sales_order_id']; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
|
||||
|
||||
<a href="<?= "download_invoice/" . $value['sales_order_id']; ?>" class="edit-button"><i class="ri-file-download-line"></i></a>
|
||||
|
||||
<a href="<?= "delete_sale/" . $value['sales_order_id']; ?>" class="delete-button"><i class="ri-delete-bin-line"></i></a>
|
||||
</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';
|
||||
}
|
||||
?>">
|
||||
<?= $value['status']; ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<a href="<?= "new_sale/" . $value['sales_order_id']; ?>" class="edit-button" title="Edit"><i class="ri-pencil-line" style="font-size: 20px;"></i></a>
|
||||
<a href="<?= "delete_sale/" . $value['sales_order_id']; ?>" class="delete-button" title="Delete"><i class="ri-delete-bin-line" style="font-size: 20px;"></i></a>
|
||||
<a href="<?= "download_invoice/" . $value['sales_order_id']; ?>" class="edit-button" title="Download"><i class="ri-download-2-fill" style="font-size: 20px;"></i></a>
|
||||
</td>
|
||||
|
||||
|
||||
<?php endif?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
<label for="inputEmail4" class="col-form-label">Vehicle<span class="text-danger">*</span></label>
|
||||
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Client"></i>' ?>
|
||||
|
||||
<select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? 'readonly' : 'required' ?>>
|
||||
<select class="form-control vehicle-select SelExample" name="vehicle_id" id="vehicle_id" <?= isset($sales['vehicle_id']) ? 'disabled' : 'required' ?>>
|
||||
|
||||
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
|
||||
<?php foreach ($vehicle as $value) : ?>
|
||||
@ -55,23 +55,27 @@
|
||||
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>(<?php echo isset($sales['status']) ? $sales['status'] : '' ?>)</label>
|
||||
<select class="form-control status-select" name="status" required data-toggle="select2">
|
||||
<?php if (isset($sales['status'])): ?>
|
||||
<?php if ($sales['status'] === 'Cancelled'): ?>
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>
|
||||
<?php if (isset($sales['status']) && $sales['status'] !== ''): ?>
|
||||
(<?= $sales['status'] ?>)
|
||||
<?php endif; ?></label>
|
||||
<select class="form-control status-select" name="status" required 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>
|
||||
<?php else: ?>
|
||||
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<?php else: ?>
|
||||
<option>Select Status</option>
|
||||
<option value="Paid" <?= $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<option value="Cancelled" <?= $sales['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<?php else: ?>
|
||||
<option value="Created" selected>Created</option>
|
||||
<option value="Paid">Paid</option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
<!-- <option value="Paid">Paid</option> -->
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><br>
|
||||
|
||||
@ -141,7 +145,7 @@
|
||||
</select>
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($salechild['qty']) ? $salechild['qty'] : '' ?>">
|
||||
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($salechild['qty']) ? $salechild['qty'] : '1' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-rate" name="unit-price[]" readonly value="<?= isset($salechild['net_price']) ? $salechild['net_price'] : '' ?>">
|
||||
@ -225,7 +229,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($sales['status']) || $sales['status'] !== 'Paid') : ?>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<button type="submit" id="editaddbutton" class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</form>
|
||||
@ -345,51 +349,77 @@
|
||||
|
||||
productarray = [];
|
||||
$(document).ready(function() {
|
||||
// Function to fetch make and model information based on make and model IDs
|
||||
function fetchMakeAndModel(makeId, modelId) {
|
||||
// Make sure makeId and modelId are valid
|
||||
if (makeId !== '' && modelId !== '') {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
make_id: makeId,
|
||||
model_id: modelId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
// Populate make and model in the input field
|
||||
var makeAndModel = response.makeName + ' ' + response.modelName;
|
||||
$('#makeAndModel').val(makeAndModel);
|
||||
|
||||
console.log(response);
|
||||
productarray = response.product;
|
||||
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Make ID or Model ID not found for the selected vehicle');
|
||||
}
|
||||
}
|
||||
|
||||
// Event listener for vehicle selection change
|
||||
$('.vehicle-select').change(function() {
|
||||
var vehicleId = $(this).val();
|
||||
|
||||
|
||||
if (vehicleId !== '') {
|
||||
// Find the selected vehicle
|
||||
var selectedVehicle = vehicles.find(function(vehicle) {
|
||||
return vehicle.vehicle_id == vehicleId;
|
||||
});
|
||||
|
||||
// Extract makeId from the selected vehicle
|
||||
|
||||
// Extract makeId and modelId from the selected vehicle
|
||||
var makeId = selectedVehicle.make;
|
||||
var modelId = selectedVehicle.model;
|
||||
console.log(modelId);
|
||||
|
||||
// Make sure makeId exists
|
||||
if (makeId !== undefined) {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
make_id: makeId,
|
||||
model_id:modelId,
|
||||
vehicle_id: vehicleId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
productarray = response.product;
|
||||
makeAndModel = response.makeName+' '+response.modelName;
|
||||
$('#makeAndModel').val(makeAndModel);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Make ID not found for the selected vehicle');
|
||||
}
|
||||
|
||||
// Fetch make and model information
|
||||
fetchMakeAndModel(makeId, modelId);
|
||||
}
|
||||
});
|
||||
|
||||
// Edit scenario: Populate make and model based on stored vehicle ID
|
||||
var storedVehicleId = "<?php echo isset($sales['vehicle_id']) ? $sales['vehicle_id'] : ''; ?>";
|
||||
if (storedVehicleId !== '') {
|
||||
// Find the selected vehicle from the vehicles array
|
||||
var selectedVehicle = vehicles.find(function(vehicle) {
|
||||
return vehicle.vehicle_id == storedVehicleId;
|
||||
});
|
||||
|
||||
// Extract makeId and modelId from the selected vehicle
|
||||
var makeId = selectedVehicle.make;
|
||||
var modelId = selectedVehicle.model;
|
||||
|
||||
// Fetch make and model information
|
||||
fetchMakeAndModel(makeId, modelId);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
<?php
|
||||
$product_json = json_encode($product);
|
||||
?>
|
||||
@ -416,10 +446,7 @@ $(document).ready(function() {
|
||||
|
||||
// Function to calculate amount based on rate and quantity
|
||||
function calculateAmount(row) {
|
||||
var rate = $(row).find('.item-rate').val();
|
||||
var quantity = $(row).find('.item-quantity').val();
|
||||
var amount = rate * quantity;
|
||||
$(row).find('.item-amount').val(amount);
|
||||
|
||||
|
||||
// Retrieve CGST and SGST values from the database for the selected product
|
||||
var productId = $(row).find('select[name="item_details[]"]').val();
|
||||
@ -432,12 +459,22 @@ $(document).ready(function() {
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + sgst;
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
var rate = $(row).find('.item-rate').val();
|
||||
var quantity = $(row).find('.item-quantity').val();
|
||||
|
||||
var amount = rate * quantity;
|
||||
console.log(amount);
|
||||
var taxamount = amount * tax/100;
|
||||
var finalamt=amount + taxamount;
|
||||
console.log("samount".samount);
|
||||
$(row).find('.item-amount').val(finalamt);
|
||||
}
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(0);
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
||||
|
||||
|
||||
// Find product details from JSON
|
||||
var product = products.find(function(item) {
|
||||
@ -450,6 +487,7 @@ $(document).ready(function() {
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
calculateAmount($(this).closest('tr'));
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
// Event listener for quantity change
|
||||
@ -472,11 +510,18 @@ $(document).ready(function() {
|
||||
|
||||
var tax = 0;
|
||||
$('.item-tax').each(function() {
|
||||
var taxPercentage = parseFloat($(this).val()) || 0;
|
||||
var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
|
||||
var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value
|
||||
tax += taxValue;
|
||||
});
|
||||
var taxPercentage = parseFloat($(this).val()) || 0;
|
||||
// console.log(taxPercentage);
|
||||
var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
|
||||
// console.log(amount);
|
||||
var qty=parseFloat($(this).closest('tr').find('.item-quantity').val()) || 0;
|
||||
// console.log(qty);
|
||||
var rate=parseFloat($(this).closest('tr').find('.item-rate').val()) || 0;
|
||||
var taxamount=rate * qty;
|
||||
// console.log(taxamount);
|
||||
var taxValue = (taxPercentage / 100) * taxamount; // Convert percentage to absolute value
|
||||
tax += taxValue;
|
||||
});
|
||||
return tax;
|
||||
}
|
||||
|
||||
@ -502,9 +547,9 @@ $(document).ready(function() {
|
||||
// Function to calculate total
|
||||
function calculateTotal() {
|
||||
var subtotal = calculateSubtotal();
|
||||
var tax = calculateTax();
|
||||
|
||||
var discount = calculateDiscount();
|
||||
var total = subtotal + tax - discount;
|
||||
var total = subtotal - discount;
|
||||
// return total;
|
||||
return Math.round(total);
|
||||
}
|
||||
@ -548,7 +593,8 @@ $(document).ready(function() {
|
||||
|
||||
$('#itemTable tbody').append(newRow);
|
||||
initializeSelect2();
|
||||
|
||||
updateCalculations();
|
||||
initializeRowCalculations(row);
|
||||
|
||||
});
|
||||
|
||||
@ -559,6 +605,10 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
|
||||
function initializeRowCalculations(row) {
|
||||
calculateAmount(row);
|
||||
updateCalculations();
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
@ -815,4 +865,11 @@ document.getElementById('reg_no').addEventListener('input', function(event) {
|
||||
.select2-container--default .select2-selection--single .select2-selection__arrow{
|
||||
top:4px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
<script>
|
||||
// Assuming you have an edit button with an ID 'editButton'
|
||||
$('#editaddbutton').click(function() {
|
||||
// Enable the vendor dropdown
|
||||
$('#vehicle_id').prop('disabled', false);
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user