Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic

This commit is contained in:
heama 2024-04-10 17:03:16 +05:30
commit 122ba8a782
5 changed files with 131 additions and 213 deletions

View File

@ -120,7 +120,8 @@ $routes->post('create_manufacturer', 'Manufacturer::create_manufacturer');
$routes->get('purchase_index', 'Purchase::purchase_index');
$routes->get("new_purchase/(:any)", "Purchase::new_purchase/$1");
$routes->get('get_product/(:any)', 'Purchase::get_product/$1');
$routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1');
$routes->post("add_purchase", "Purchase::add_purchase");
$routes->get("delete_purchase/(:any)", "Purchase::delete_purchase/$1");
// Reorder Level//
$routes->get('reorder_level_index', 'Reorderlevel::reorder_level_index');
$routes->get('reorder_level_index', 'Reorderlevel::reorder_level_index');

View File

@ -21,187 +21,123 @@ class Purchase extends BaseController
{
$PurchaseOrderModel = new PurchaseOrderModel();
$purchase = $PurchaseOrderModel->findAll();
$purchase = $PurchaseOrderModel->select('purchase_order.*, vendor.vendor_name')
->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id')
->findAll();
// echo "<pre>";
// print_r($product);die;
$data['purchase']=$purchase;
echo "<pre>";
print_r($data);die;
// echo "<pre>";
// print_r($data);die;
return view('purchase_list',$data);
}
public function new_purchase($purchase_id)
public function new_purchase($purchase_order_id)
{
if ($purchase_id === '0') {
if ($purchase_order_id === '0') {
$data['purchase'] = [];
$PurchaseOrderModel = new PurchaseOrderModel();
$ProductModel = new ProductModel();
$product = $ProductModel->select('product_id,product_name')->findAll();
$VendorModel = new VendorModel();
$vendor = $VendorModel->select('vendor_id,vendor_name')->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();
$data['branch'] = $branch;
$data['business'] = $business;
$data['page_name']="Add Purchase Order";
$data['product']=$product;
$data['vendor']=$vendor;
} else if ($purchase_id !== '0') {
$data['page_name']="Edit Product";
$ProductModel = new ProductModel();
$products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
} 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['products']=$products;
$BikemakeModel = new BikemakeModel();
$data['make'] = $BikemakeModel->findAll();
$BikemodelsModel = new BikemodelsModel();
$make_id = $products['make_id'];
$data['models'] = $BikemodelsModel->where('make_id', $make_id)->findAll();
$tax=$ProductModel->getTax();
$data['tax']=$tax;
$VendorModel = new VendorModel();
$data['vendors']=$VendorModel->findAll();
$vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
$data['vendor']=$vendor;
$data['purchase'] = $purchase;
$data['vendor_id'] = $purchase['vendor_id'];
}
$data['purchase_id'] = $purchase_id;
// echo "<pre>";
// print_r($data);die;
echo view('purchase_form',$data);
}
public function add_purchase()
{
$PurchaseOrderModel = new PurchaseOrderModel();
$data = [
'product_id' => $this->request->getPost('product_id'),
'vendor_id' => $this->request->getPost('vendor_id'),
'product_quantity' => $this->request->getPost('product_quantity'),
'unit_price' => $this->request->getPost('unit_price'),
'total_price' => $this->request->getPost('total_price'),
'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_addresss' => $this->request->getPost('billing_addresss'),
'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_addresss' => $this->request->getPost('shipping_addresss'),
'shipping_state' => json_encode($this->request->getPost('shipping_state')),
'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'),
'description' => $this->request->getPost('description'),
];
// $product_id = $this->request->getPost('product_id');
// echo "<pre>";
// print_r($this->request->getPost());die;
$purchase_order_id = $this->request->getPost('purchase_order_id');
// if (!empty($product_id)) {
if (!empty($purchase_order_id)) {
// $PurchaseOrderModel->update($product_id, $data);
// } else {
$PurchaseOrderModel->update($purchase_order_id, $data);
} else {
$PurchaseOrderModel->insert($data);
// }
}
return redirect()->to('product_index');
return redirect()->to('purchase_index');
}
public function delete_product($product_id)
public function delete_purchase($purchase_order_id)
{
$model = new ProductModel();
$where = ['product_id' => $product_id, 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id')]; // Assuming 'isactive' is a column in your database
$existingProduct = $model->where($where)->first();
$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 ($existingProduct) {
if ($existingPurchase) {
$data['isactive'] = 0;
if ($model->update($product_id, $data)) {
if ($PurchaseOrderModel->update($purchase_order_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$product_id);
$this->logger->info("Purchase Order: has been Inactivated successfully. Inactivated ID = ".$purchase_order_id);
}
}
return redirect()->to('product_index');
return redirect()->to('purchase_index');
}
// Retrieve the make_id from the AJAX request
public function get_vendors_by_model()
{
$model_ids = $this->request->getPost('model_ids');
$make_id = $this->request->getPost('make_id');
$vendorModel = new VendorModel();
$Vendors = $vendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
if($Vendors){
$data = [];
foreach ($model_ids as $modelKey => $modelValue)
{
foreach ($Vendors as $vendorsKey => $vendorsValue)
{
$modelsArray = json_decode($vendorsValue['model'], true);
if (is_array($modelsArray))
{
$findIfModelExist = array_search($modelValue, $modelsArray);
if ($findIfModelExist !== false)
{
array_push($data,$vendorsValue);
}
}
}
}
if (count($data)) {
$arrayOfArrays = array_map(function($obj) {
return (array) $obj;
}, $data);
// Remove duplicates based on string representation of each object
$uniqueArray = array_map('unserialize', array_unique(array_map('serialize', $arrayOfArrays)));
// Convert the unique array of associative arrays back to an array of objects
$uniqueObjectsArray = array_map(function($arr) {
return (object) $arr;
}, $uniqueArray);
return $this->response->setJSON($uniqueArray);
} else {
return $this->response->setJSON([]);
}
}else {
return $this->response->setJSON([]);
}
}
public function get_product($product_id)
public function get_vendor($vendor_id)
{
$ProductModel = new ProductModel();
$BranchModel = new BranchModel();
$BusinessModel = new BusinessModel();
$VendorModel = new VendorModel();
$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();
$products =$VendorModel->where('vendor_id',$vendor_id)->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray();
$products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
if ($products['prefered_vendor']) {
$VendorModel = new VendorModel();
$products +=$VendorModel->where('vendor_id',$products['prefered_vendor'])->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray();
}
$products['branch']=$branch;
$products['business']=$business;
return json_encode($products);
}

View File

@ -5,7 +5,7 @@ class PurchaseOrderModel extends Model
{
protected $table = 'purchase_order';
protected $primaryKey = 'purchase_order_id';
protected $allowedFields = ['purchase_order_id','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','product_id','product_quantity','unit_price','total_price','order_date','contact_person_name','contact_person_mobile'];
protected $allowedFields = ['purchase_order_id','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','contact_person_mobile','description'];
}

View File

@ -5,7 +5,7 @@
<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() . "product_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<a href="<?= base_url() . "purchase_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<ol class="breadcrumb m-0">
</li>
@ -22,38 +22,25 @@
<div class="card-body">
<h4 class="header-title"></h4>
<form action="<?= base_url() . "add_purchase"; ?>" method="post">
<input type="text" id="purchase_order_id" name="purchase_order_id" value="<?=isset($purchase_id) && !empty($purchase_id) ? $purchase_id : '' ?>" hidden>
<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">Product<span class="text-danger">*</span></label>
<select class="form-control" name="product_id" id="product_id">
<option value="0">Select Product</option>
<?php foreach ($product as $item): ?>
<option value="<?= $item['product_id'] ?>"><?= $item['product_name'] ?></option>
<label for="make" class="col-form-label">Vendor<span class="text-danger">*</span></label>
<select class="form-control" 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="model" class="col-form-label">Vendor<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="vendor_id" id="vendor_id">
</div>
<div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Product Quantity<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="product_quantity" id="product_quantity" placeholder="Product Quantity" value="<?= isset($products['product_quantity']) ? $products['product_quantity'] : '' ?>" required>
</div>
<div class="form-group col-md-4">
<label for="vendor" class="col-form-label">Unit Price<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="unit_price" id="unit_price">
</div>
<div class="form-group col-md-4">
<label for="vendor" class="col-form-label">Total Price<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="total_price" id="total_price">
</div>
</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="<?= isset($purchase['order_date']) ? $purchase['order_date'] : '' ?>" >
<input type="date" class="form-control" name="order_date" id="order_date" value="<?= isset($purchase['order_date']) ? date('Y-m-d', strtotime($purchase['order_date'])) : '' ?>" >
</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>
@ -65,57 +52,57 @@
<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">Draft</option>
<option value="released">Released</option>
<option value="cancel">Cancel</option>
<option value="draft" <?= isset($purchase['status']) && $purchase['status'] == 'draft' ? 'selected' : '' ?>>Draft</option>
<option value="released" <?= isset($purchase['status']) && $purchase['status'] == 'released' ? 'selected' : '' ?>>Released</option>
<option value="cancel" <?= isset($purchase['status']) && $purchase['status'] == 'cancel' ? 'selected' : '' ?>>Cancel</option>
</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_addresss" class="col-form-label">Billing Addresss<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="billing_addresss" id="billing_addresss" placeholder="Billing Addresss"value="<?= isset($purchase['billing_addresss']) ? $purchase['billing_addresss'] : '' ?>" required>
<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($purchase['billing_state']) ? $purchase['billing_state'] : '' ?>" >
<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($purchase['billing_city']) ? $purchase['billing_city'] : '' ?>" required>
<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($purchase['billing_postal_code']) ? $purchase['billing_postal_code'] : '' ?>" required>
<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_addresss" class="col-form-label">Shipping Addresss<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="shipping_addresss" id="shipping_addresss" placeholder="Shipping Addresss"value="<?= isset($purchase['shipping_addresss']) ? $purchase['shipping_addresss'] : '' ?>" required>
<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($purchase['shipping_state']) ? $purchase['shipping_state'] : '' ?>" >
<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($purchase['shipping_city']) ? $purchase['shipping_city'] : '' ?>" required>
<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($purchase['shipping_postal_code']) ? $purchase['shipping_postal_code'] : '' ?>" required>
<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>
<h4 class="header-title">Description Details :</h4><br>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputPassword4" class="col-form-label">Description</label>
<textarea class="form-control" name="description" placeholder="Description"value="<?= isset($products['description']) ? $products['description'] : '' ?>" required>
</textarea>
<textarea class="form-control" name="description" placeholder="Description" required><?= isset($purchase['description']) ? $purchase['description'] : '' ?></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
@ -168,51 +155,45 @@ $(document).ready(function(){
$(document).ready(function() {
$('#product_id').change(function() {
var product_id = $(this).val();
// $('#vendor_id').change(function() {
// var vendor_id = $(this).val();
$.ajax({
url: '<?php echo base_url('get_product/') ?>' + product_id,
type: 'GET',
dataType: 'json',
success: function(response) {
console.log(response);
// $.ajax({
// url: '<?php echo base_url('get_vendor/') ?>' + vendor_id,
// type: 'GET',
// dataType: 'json',
// success: function(response) {
// if (response) {
if (response) {
$('#unit_price').val(response.unit_price);
$('#vendor_id').val(response.vendor_name);
$('#vendor_id').attr('data-id', response.prefered_vendor);
$('#product_quantity').val(response.reorder_level);
$('#contact_person_name').val(response.contact_person_name1);
$('#contact_person_mobile').val(response.contact_person_mobile1);
$('#total_price').val(response.unit_price * response.reorder_level);
// $('#contact_person_name').val(response.contact_person_name1);
// $('#contact_person_mobile').val(response.contact_person_mobile1);
// $('#total_price').val(response.unit_price * response.reorder_level);
var currentDate = new Date().toISOString().split('T')[0]; // Get current date in yyyy-mm-dd format
$('#order_date').val(currentDate);
// var currentDate = new Date().toISOString().split('T')[0]; // Get current date in yyyy-mm-dd format
// $('#order_date').val(currentDate);
$('#shipping_addresss').val(response.branch.address);
$('#shipping_state').val(response.branch.state);
$('#shipping_city').val(response.branch.city);
$('#shipping_postal_code').val(response.branch.postal_code);
// $('#shipping_addresss').val(response.branch.address);
// $('#shipping_state').val(response.branch.state);
// $('#shipping_city').val(response.branch.city);
// $('#shipping_postal_code').val(response.branch.postal_code);
$('#billing_addresss').val(response.business.address);
$('#billing_state').val(response.business.state);
$('#billing_city').val(response.business.city);
$('#billing_postal_code').val(response.business.postal_code);
console.log(response.branch);
}
// $('#billing_addresss').val(response.business.address);
// $('#billing_state').val(response.business.state);
// $('#billing_city').val(response.business.city);
// $('#billing_postal_code').val(response.business.postal_code);
// console.log(response.branch);
// }
},
error: function(xhr, status, error) {
// Handle error
console.error(xhr.responseText);
}
});
});
// },
// error: function(xhr, status, error) {
// // Handle error
// console.error(xhr.responseText);
// }
// });
// });
});
</script>

View File

@ -3,7 +3,7 @@
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Purchase List </h4>
<h4 class="page-title">Purchase Order List </h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class=""> <a href="<?= base_url() . "new_purchase/0"; ?>" class="btn btn-primary waves-effect"> <i class="ri-add-line"></i></a>
@ -28,32 +28,32 @@
<thead>
<tr>
<th>Product Name</th>
<th>Actions</th>
<th>Vendor Name</th>
<th>Order Date</th>
<th>Contact Person Name</th>
<th>Contact Person Mobile</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($products as $value) :
<?php foreach ($purchase as $value) :
if ($value['isactive'] == 1) : ?>
<tr>
<td><?= $value['product_name']; ?></td>
<td><?= $value['product_category']; ?></td>
<?php if(!$manufacturer_id) { ?><td><?= $value['serial_no']; ?></td><?php } ?>
<td><?= number_format($value['unit_price']); ?></td>
<td><?= $value['qty_stock']; ?></td>
<td><?= $value['cgst']; ?>%</td>
<td><?= $value['sgst']; ?>%</td>
<td><?= $value['vendor_name']; ?></td>
<td><?= $value['order_date']; ?></td>
<td><?= $value['contact_person_name']; ?>%</td>
<td><?= $value['contact_person_mobile']; ?>%</td>
<td><?= $value['status']; ?>%</td>
<!-- Call the model method -->
<?php if(!$manufacturer_id) { ?>
<td>
<a href="<?= "new_product/" . $value['product_id']; ?>" class="edit-button"><i
<a href="<?= "new_purchase/" . $value['purchase_order_id']; ?>" class="edit-button"><i
class="ri-pencil-line"></i></a>
<a href="<?= "delete_product/" . $value['product_id']; ?>"
<a href="<?= "delete_purchase/" . $value['purchase_order_id']; ?>"
class="delete-button"><i class="ri-delete-bin-line"></i></a>
</td>
<?php } ?>
<?php endif?>
<?php endforeach; ?>