FEATURE_PURCHASE:AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-10 13:25:24 +05:30
parent cfd1e9ec4c
commit 9197a5f76b
9 changed files with 551 additions and 16 deletions

View File

@ -86,7 +86,7 @@ $routes->get('dashboard', 'Users::dashboard');
//---------------------- Make And Model | Service | Manufacturer
//---------------------- Make And Model | Service | Manufacturer | Inventory->Purchase
// Make
$routes->get('make_index', 'Make::index');
$routes->post('create_make', 'Make::create_make');
@ -112,3 +112,10 @@ $routes->get("delete_service/(:any)", "Service::delete_service/$1");
$routes->get('spare_manufacturer_index', 'Manufacturer::index');
$routes->post('create_manufacturer', 'Manufacturer::create_manufacturer');
// Purchase
$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->post("add_purchase", "Purchase::add_purchase");

View File

@ -35,11 +35,11 @@ class Manufacturer extends BaseController
{
try {
$manufacturer_name = $this->request->getPost('manufacturername');
$quantity = $this->request->getPost('quantity');
$quality = $this->request->getPost('quality');
$ManufacturerModel = new ManufacturerModel();
$data = [
'manufacturer_name' => $manufacturer_name,
'quantity' => $quantity,
'quality' => $quality,
];
$inserted = $ManufacturerModel->insert($data);
if ($inserted) {

View File

@ -6,6 +6,7 @@ use App\Models\ProductModel;
use App\Models\BikemakeModel;
use App\Models\VendorModel;
use App\Models\BikemodelsModel;
use App\Models\ManufacturerModel;
class Products extends BaseController
@ -23,9 +24,12 @@ class Products extends BaseController
if ($manufacturer_id) {
$ProductModel = new ProductModel();
$ManufacturerModel = new ManufacturerModel();
$products = $ProductModel->where('manufacturer_id',$manufacturer_id)->findAll();
$manufacturer = $ManufacturerModel->where('manufacturer_id',$manufacturer_id)->select('manufacturer_name')->first();
$data['products']=$products;
$data['manufacturer_id'] = $manufacturer_id;
$data['manufacturer_name'] = $manufacturer['manufacturer_name'];
return view('product_list',$data);
} else {

View File

@ -0,0 +1,209 @@
<?php
namespace App\Controllers;
use App\Models\PurchaseOrderModel;
use App\Models\ProductModel;
use App\Models\VendorModel;
use App\Models\BranchModel;
use App\Models\BusinessModel;
class Purchase extends BaseController
{
public $session;
public function __construct()
{
$this->session = session();
}
public function purchase_index()
{
$PurchaseOrderModel = new PurchaseOrderModel();
$purchase = $PurchaseOrderModel->findAll();
// echo "<pre>";
// print_r($product);die;
$data['purchase']=$purchase;
echo "<pre>";
print_r($data);die;
return view('purchase_list',$data);
}
public function new_purchase($purchase_id)
{
if ($purchase_id === '0') {
$data['purchase'] = [];
$PurchaseOrderModel = new PurchaseOrderModel();
$ProductModel = new ProductModel();
$product = $ProductModel->select('product_id,product_name')->findAll();
$data['page_name']="Add Purchase Order";
$data['product']=$product;
} else if ($purchase_id !== '0') {
$data['page_name']="Edit Product";
$ProductModel = new ProductModel();
$products=$ProductModel->where('product_id', $product_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();
}
$data['purchase_id'] = $purchase_id;
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_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_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');
// if (!empty($product_id)) {
// $PurchaseOrderModel->update($product_id, $data);
// } else {
$PurchaseOrderModel->insert($data);
// }
return redirect()->to('product_index');
}
public function delete_product($product_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();
if ($existingProduct) {
$data['isactive'] = 0;
if ($model->update($product_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$product_id);
}
}
return redirect()->to('product_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)
{
$ProductModel = new ProductModel();
$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();
$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

@ -143,6 +143,9 @@
<li>
<a href="<?php echo base_url('vendor_index') ?>">Vendor</a>
</li>
<li>
<a href="<?php echo base_url('purchase_index') ?>">Purchase</a>
</li>
</ul>
</div>
</li>

View File

@ -26,7 +26,7 @@
<thead>
<tr>
<th>Manufacturer </th>
<th>Quantity</th>
<th>Quality</th>
<th>Action</th>
</tr>
</thead>
@ -34,7 +34,7 @@
<?php foreach ($manufacturer as $item): ?>
<tr>
<td><?php echo $item['manufacturer_name']; ?></td>
<td><?php echo $item['quantity']; ?></td>
<td><?php echo $item['quality']; ?></td>
<td>
<a href="<?= "product_index/" . $item['manufacturer_id']; ?>" class="view-list-button" title="Model List" style="margin-left: 16px;">
<i class="ri-list-check-2 icon-large"></i>
@ -66,13 +66,13 @@
<input class="form-control" type="text" id="manufacturer_name" required="" placeholder="Make Name....">
</div>
<div class="form-group">
<label for="manufacturername">Quantity</label>
<select name="quantity" id="quantity" class="form-control" style="border-color: lightgray;color: #6c757d;">
<option value="0">Select Quantity</option>
<option value="q1">Q1</option>
<option value="q2">Q2</option>
<option value="q3">Q3</option>
<option value="q4">Q4</option>
<label for="manufacturername">Quality</label>
<select name="quality" id="quality" class="form-control" style="border-color: lightgray;color: #6c757d;">
<option value="0">Select Quality</option>
<option value="Q1">Q1</option>
<option value="Q2">Q2</option>
<option value="Q3">Q3</option>
<option value="Q4">Q4</option>
</select>
</div>
@ -98,7 +98,7 @@
function submitMake(params) {
var formData = {
manufacturername: $('#manufacturer_name').val(),
quantity: $('#quantity').val()
quality: $('#quality').val()
};
$.ajax({

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">Product List</h4>
<h4 class="page-title">Product List <?= isset($manufacturer_id) && !empty($manufacturer_id) ? $manufacturer_name : '' ?></h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<?php if(!$manufacturer_id) { ?>
@ -32,7 +32,7 @@
<tr>
<th>Product Name</th>
<th>Category</th>
<th>Serial Number</th>
<?php if(!$manufacturer_id) { ?><th>Serial Number</th><?php } ?>
<th>Unit Price</th>
<th>Qty in Stock</th>
<th>Sgst</th>
@ -48,7 +48,7 @@
<tr>
<td><?= $value['product_name']; ?></td>
<td><?= $value['product_category']; ?></td>
<td><?= $value['serial_no']; ?></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>

242
app/Views/purchase_form.php Normal file
View File

@ -0,0 +1,242 @@
<?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() . "product_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">
<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>
<?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 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'] : '' ?>" >
</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'] : '' ?>" 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">Draft</option>
<option value="released">Released</option>
<option value="cancel">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>
</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'] : '' ?>" >
</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>
</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>
</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>
</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'] : '' ?>" >
</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>
</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>
</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>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
<?php include('layout/footer.php'); ?>
<script>
$(document).ready(function() {
// Check SGST checkbox by default
$('#sgstCheckbox').prop('checked', true);
$('#sgstValue').removeClass('d-none');
// Check CGST checkbox by default
$('#cgstCheckbox').prop('checked', true);
$('#cgstValue').removeClass('d-none');
// Handle change event for SGST checkbox
$('#sgstCheckbox').change(function() {
if ($(this).is(":checked")) {
$('#sgstValue').removeClass('d-none');
} else {
$('#sgstValue').addClass('d-none');
}
});
// Handle change event for CGST checkbox
$('#cgstCheckbox').change(function() {
if ($(this).is(":checked")) {
$('#cgstValue').removeClass('d-none');
} else {
$('#cgstValue').addClass('d-none');
}
});
});
</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();
});
</script>
<script>
$(document).ready(function() {
$('#product_id').change(function() {
var product_id = $(this).val();
$.ajax({
url: '<?php echo base_url('get_product/') ?>' + product_id,
type: 'GET',
dataType: 'json',
success: function(response) {
console.log(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);
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);
$('#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);
}
});
});
});
</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>

View File

@ -0,0 +1,70 @@
<?php include('layout/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Purchase 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>
</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-buttons" class="table table-striped dt-responsive nowrap w-100"
style="width:100% !important;">
<thead>
<tr>
<th>Product Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($products 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>
<!-- Call the model method -->
<?php if(!$manufacturer_id) { ?>
<td>
<a href="<?= "new_product/" . $value['product_id']; ?>" class="edit-button"><i
class="ri-pencil-line"></i></a>
<a href="<?= "delete_product/" . $value['product_id']; ?>"
class="delete-button"><i class="ri-delete-bin-line"></i></a>
</td>
<?php } ?>
<?php endif?>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<?php include('layout/footer.php'); ?>