siddharth_application/application/controllers/inwardgateregister.php
venbatechnologies@gmail.com 7e336808ea ogr bug fix
2018-04-10 10:17:05 +05:30

581 lines
16 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : Inward Gate Register Controller (security)
* User Class to control all user related operations.
* @author : Saravana kumar
* @version : 1.1
* @since : 8 Jun 2017
*/
class inwardgateregister extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('inwardgateregister_model');
$this->load->library('session');
$this->load->library('form_validation');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the user
*/
public function index()
{
$this->global['pageTitle'] = 'Siddharth : Inward Gate Register';
$this->loadViews("viewinwardgateregister", $this->global,NULL , NULL);
}
function viewIGRDetails()
{
$this->load->model('inwardgateregister_model');
$this->global['pageTitle'] = 'Siddharth : Inward Gate Register Details';
$data['IGR']= $this->inwardgateregister_model->igrListing();
$this->loadViews("viewIGRDetails",$this->global,$data,NULL);
}
function addinwardgateregister()
{
$this->load->model('inwardgateregister_model');
$this->global['pageTitle'] = 'Siddharth : Add Inward Gate Register';
$data['PO_NO'] = $this->inwardgateregister_model->getpurchaseorder();
//print_r($data['PO_NO']);
$this->loadViews("inwardgateregister", $this->global, $data, NULL);
}
function addoutwardgateregister()
{
$this->load->model('inwardgateregister_model');
$this->global['pageTitle'] = 'Siddharth : Add Outward Gate Register';
$data['Customer'] = $this->inwardgateregister_model->getCustomer();
$data['Supplier'] = $this->inwardgateregister_model->getSupplier();
//$data['Invoice'] = $this->inwardgateregister_model->getInvoice();
//print_r($data['PO_NO']);
$this->loadViews("ogr", $this->global, $data, NULL);
}
function ViewOgr()
{
$this->load->model('inwardgateregister_model');
$this->global['pageTitle'] = 'Siddharth : View Outward Gate Register';
$data['OGR_Data'] = $this->inwardgateregister_model->getOGRData();
//print_r($data['OGR_Data']);
$this->loadViews("ogrlist", $this->global, $data, NULL);
}
function EditOGR()
{
$OGRNO = $_GET['OGRNO'];
$this->global['pageTitle'] = 'Siddharth : View Outward Gate Register';
$data['OGR_Data'] = $this->inwardgateregister_model->getOGRDataforedit($OGRNO);
$data['OGR_line'] = $this->inwardgateregister_model->getOGRlineDataforedit($OGRNO);
$this->loadViews("editogr", $this->global, $data, NULL);
}
function GetInvoices()
{
$CustomerId = $this->input->post('customerId');
$data = $this->inwardgateregister_model->getInvoice($CustomerId);
echo json_encode($data);
}
function GetPO()
{
$supplierId = $this->input->post('supplierId');
$data = $this->inwardgateregister_model->getPO($supplierId);
echo json_encode($data);
}
function getPODetails()
{
$PONO = $this->input->post('PONO');
$data = $this->inwardgateregister_model->getPODetails($PONO);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getPOmaterialDetails()
{
$PONO= $this->input->post('PONO');
$materialcode= $this->input->post('materialcode');
$data= $this->inwardgateregister_model->getPOmaterialDetails($PONO,$materialcode);
echo json_encode($data);
}
function getPOmaterial()
{
$PONO = $this->input->post('PONO');
$data = $this->inwardgateregister_model->getPOmaterial($PONO);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getDateformat($Val)
{
$date = new DateTime($Val,new DateTimeZone('Asia/Kolkata'));
// print_r($date);
$retDate = $date->format('Y-m-d H:i:s');
return $retDate;
}
function IGRITEM()
{
$PO = $this->input->post('id');
$CreatedBy = $this->session->userdata('userId');
$this->inwardgateregister_model->UpdatePOMaster($PO,$CreatedBy);
$data = $this->inwardgateregister_model->viewpurchaseorder($PO);
echo json_encode($data);
}
function uploadFile()
{
//echo "INSIDE UPLOAFD";
//$this->load->library('upload')
$pathinfo = pathinfo($_FILES['myfile']['name']);
$config['upload_path'] = 'uploads/Igrfiles/';
$config['allowed_types'] = 'png|jpg|jpeg|pdf|docx';
$config['file_name'] = $_FILES['myfile']['name'];
// $config['overwrite'] = true;
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('myfile'))
{
$uploadData = $this->upload->data();
$uploadfilename = $uploadData['file_name'];
return $uploadfilename;
}
else
{
$error = array('error' => $this->upload->display_errors());
$uploadfilename = '';
print_r($error);
return 0;
}
}
function addNewigr()
{
// echo "add";
// die();
$PONO = $this->input->post('PONO');
$DeliveryChellanOrInvoiceNo = $this->input->post('InvoiceNo');
$DeliveryChellan = $this->input->post('InvoiceDate');
$DeliveryChellanDate = $this->getDateformat($DeliveryChellan);
$VehicleNo = $this->input->post('VehicleNo');
$CourierNo = $this->input->post('CourierNo');
$CreatedBy = $this->session->userdata('userId');
//$Remarks = $this->input->post('Remarks');
$RowCount = $this->input->post('txtRowCount');
//echo $RowCount;
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$createddt = $dt->format('Y-m-d H:i:s');
$IGRStatus = IGR_CREATED;
$document = null;
$fs = 0;
if(!empty($_FILES['myfile']['name']))
{
//echo "FILE AVAILABLE";
$config['file_name'] = $_FILES['myfile']['name'];
$config['upload_path'] = 'uploads/Igrfiles/';
$config['allowed_types'] = 'png|jpg|jpeg|pdf|docx';
$path = $config['upload_path'];
$filename = $config['file_name'];
$document = $path.$filename;
//echo $document;
$fs = $this->uploadFile();
$document = $path.$fs;
//echo $document;die();
}
//echo $RowCount;
$igr = array();
$igr = array('PONO'=>$PONO,'VehicleNo'=>$VehicleNo,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanOrInvoiceNo,'DeliveryChellanDate'=>$DeliveryChellanDate,'CourierNo'=>$CourierNo,'IGRStatus'=>$IGRStatus,'CreatedBy'=>$CreatedBy,'CreatedDate' =>$createddt,'file'=>$document);
//print_r($igr);die();
$igrM = $this->inwardgateregister_model->addigrM($igr);
$OGRStatus=IGR_CREATED;
$check_OGRPO= $this->inwardgateregister_model->update_OGR($PONO,$OGRStatus);
$IGRNO = '';
if(count($igrM)>0)
{
foreach ($igrM as $key ) {
$IGRNO=$key->IGRNO;
}
}
//echo $IGRNO;
$IGRItemStatus = REQITEM_NEW;
for ($i = 1; $i <= $RowCount; $i++)
{
$MaterialCode = trim($this->input->post('MaterialCode'.$i));
$QuantityAsPerInvoice = trim($this->input->post('txtQuantityAsPerInvoice'.$i));
$OrderedQuantity = trim($this->input->post('OrderedQuantity'.$i));
$ReceivedQty = trim($this->input->post('txtReceivedQuantity'.$i));
$PendingQty = $this->input->post('txtPendingQty'.$i);
//echo $QuantityAsPerInvoice;
//echo $PendingQty.'ReceivedQty'.$ReceivedQty;
//echo ' ';
if(strlen($QuantityAsPerInvoice)>0 && $QuantityAsPerInvoice != '0')
{
$Remarks = $this->input->post('txtRemarks'.$i);
$ItemStatus = '';
//if($QuantityAsPerInvoice == $OrderedQuantity)
if($PendingQty == 0.00 )
{
$ItemStatus = IGR_CREATED;
}
else
{
$ItemStatus = POLINEITEM_IGRPARTIAL_CREATED;
}
$CreatedBy = $this->session->userdata('userId');
$igrDetails = array('IGRNO'=>$IGRNO,'MaterialCode'=>$MaterialCode,'QuantityAsPerInvoice'=>$QuantityAsPerInvoice,'Remarks'=>$Remarks,'IGRItemStatus'=>$IGRItemStatus,'CreatedBy'=>$CreatedBy,'CreatedDate'=>$createddt);
$igrD = $this->inwardgateregister_model->addigrD($igrDetails);
$Recqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONO,$MaterialCode);
$ReceivedQuantity = 0.00;
if(count($Recqty)>0)
{
foreach ($Recqty as $key ) {
$ReceivedQuantity=$key->ReceivedQuantity;
}
}
$totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice;
//echo '';
$POLineItem = array('ReceivedQuantity'=>$totalReceivedqty,'Status'=>$ItemStatus,'UpdateBY'=>$CreatedBy,'UpdatedOn'=>$createddt );
$this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$PONO,$MaterialCode);
}
}
$this->inwardgateregister_model->UpdatePOMaster($PONO,$CreatedBy);
echo "<script>alert('Successfully Created IGR Number:$IGRNO'); window.location.href='viewIGRDetails';</script>";
//echo 'Successfully Created IGR Number:'. $IGRNO;
}
function ViewIGR()
{
$IGRNO= $this->input->post('id');
//print_r($IGRNO);
$data = $this->inwardgateregister_model->viewigr($IGRNO);
// print_r( $data);
echo json_encode($data);
}
function pageNotFound()
{
$this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
function AddOgr()
{
//echo "string";
$type=$this->input->post('type');
$Supplier = $this->input->post('sup');
$Date = $this->input->post('Date');
$vehicle =$this->input->post('Vehicle');
$driver = $this->input->post('drive');
if($type == 1)
{
$invoice =$this->input->post('invno');
$Otype='Invoice';
$Status ='ST063';
$ogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver
,'PONO_INV'=>$invoice,'VehicleNo'=>$vehicle,'Status'=>$Status);
$addogrmaster= $this->inwardgateregister_model->AddOGR($ogrmaster);
$OGRNO = '';
if(count($addogrmaster)>0)
{
foreach($addogrmaster as $add)
{
$OGRNO = $add->OGRNO;
}
}
$itemcode =$this->input->post('itemcode');
$Description = $this->input->post('Description');
$invoutwardqty = $this->input->post('invoutwardqty');
$Ogrline= array('OGRNO'=>$OGRNO,'MaterialCode'=>$itemcode,'OutwardQty'=>$invoutwardqty,'Status'=>$Status);
$addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline);
if((count($addogrmaster)>0)&&(count($addOgrline>0)))
{
echo "Saved Successfully OGR No is OGR".$OGRNO;
}
}
else if($type == 2)
{
//die();
$pono =$this->input->post('pono');
//$type='PO';
$Otype='PO';
//$Status='ST063';
$row= $this->input->post('rowcount');
$ogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver
,'PONO_INV'=>$pono,'VehicleNo'=>$vehicle);
//$Igr_Details= $this->inwardgateregister_model->GetIGR_Details($pono);
$addogrmaster= $this->inwardgateregister_model->AddOGR($ogrmaster);
$pocheck= $this->inwardgateregister_model->check_PO($pono);
$IsPOExist=0;
if(count($pocheck)>0)
{
$IsPOExist=1;
}
//print_r($addogrmaster);
$OGRNO = '';
//echo count($addogrmaster);
if(count($addogrmaster)>0)
{
foreach($addogrmaster as $add)
{
$OGRNO = $add->OGRNO;
}
}
for($i=1;$i<=$row;$i++)
{
$MaterialCode = $this->input->post('materialcode'.$i);
$OutwardQty = $this->input->post('outward'.$i);
$rejqty = $this->input->post('RejectedQty'.$i);
$balance_Qty= $rejqty-$OutwardQty;
//$balance_Qty = $this->input->post('pendingoutward'.$i);
$Outwardtotal = $OutwardQty;
$allowed= $this->input->post('allowed'.$i);
if($MaterialCode != '' && $OutwardQty !='')
{
//echo $IsPOExist;
// $preqty= $this->inwardgateregister_model->GetPreSavedQty($pono,$MaterialCode);
$polqty= $this->inwardgateregister_model->getPOLineItemReceivedQty($pono,$MaterialCode);
// print_r($preqty);
$ReceivedQuantity = 0.00;
if(count($polqty)>0)
{
foreach ($polqty as $key )
{
$ReceivedQuantity=$key->ReceivedQuantity;
}
}
$totalReceivedqty = $ReceivedQuantity - $Outwardtotal;
if($OutwardQty==$allowed)
{
$Status='ST063';
}
else
{
$Status='ST064';
}
$POLineItem = array('ReceivedQuantity'=>$totalReceivedqty,'OGR_Status'=>$Status);
$this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$pono,$MaterialCode);
$Ogrline= array('OGRNO'=>$OGRNO,'MaterialCode'=>$MaterialCode,'OutwardQty'=>$Outwardtotal,'Status'=>$Status,'balance_Qty'=>$balance_Qty);
$addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline);
$updateogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver
,'PONO_INV'=>$pono,'VehicleNo'=>$vehicle,'Status'=>$Status);
$updateogrmaster= $this->inwardgateregister_model->UpdateOGR($updateogrmaster,$OGRNO);
$postatus=array('Status'=>OGR_COMPLETE);
//$this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$PONO,$MaterialCode);
$this->inwardgateregister_model->UpdatePOMasterOGR($postatus,$pono);
}
}
//$this->inwardgateregister_model->UpdatePOMaster($PONO,$CreatedBy);
//$this->inwardgateregister_model->updateogrpomaster($pono);
if((count($addogrmaster)>0)&&(count($addOgrline)>0) && (count($updateogrmaster)>0))
{
echo "Saved Successfully OGR No is OGR".$OGRNO;
}
}
else if($type ==3)
{
$Otype='SERVICE';
$Status ='ST063';
$ogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver,'VehicleNo'=>$vehicle,'Status'=>$Status);
$addogrmaster= $this->inwardgateregister_model->AddOGR($ogrmaster);
//print_r($addogrmaster);
$OGRNO = '';
//echo count($addogrmaster);
if(count($addogrmaster)>0)
{
foreach($addogrmaster as $add)
{
$OGRNO = $add->OGRNO;
}
}
$material= $this->input->post('material');
$name= $this->input->post('name');
$pooutward= $this->input->post('pooutward');
$destination= $this->input->post('destination');
$Ogrline= array('OGRNO'=>$OGRNO,'MaterialCode'=>$material,'OutwardQty'=>$pooutward,'Destination'=>$destination,'Status'=>$Status,'Material_Name'=>$name);
$addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline);
if((count($addogrmaster)>0)&&(count($addOgrline>0)))
{
echo "Saved Successfully OGR No is OGR".$OGRNO;
}
}
}
}
?>