siddharth_application/application/controllers/servicepurchaseorder.php
venbatechnologies@gmail.com e8aadd1635 access control
2017-12-01 17:41:33 +05:30

508 lines
20 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : purchaseorder (PurchaseorderController)
* User Class to control all user related operations.
* @author : VenbaMail Mali
* @version : 1.1
* @since : 15 Feb 2016
*/
class servicepurchaseorder extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('purchaseorder_model');
$this->load->library('session');
$this->load->library('form_validation');
$this->load->model('requistion_model');
$this->isLoggedIn();
}
function viewServicePOReportForBilling()
{
$this->global['pageTitle'] = 'Siddharth : Service Purchase Order for Billing';
$data["Billing"] = $this->purchaseorder_model->GetServicePOListforBilling();
//print_r($data["Billing"]);
if($this->DEPCode == FINANCE)
{
$this->loadViews("serviceporeport", $this->global,$data,null);
}
else
{
$this->loadViews("access", $this->global,$data,null);
}
}
function UpdateServicePOStatus()
{
$this->global['pageTitle'] = 'Siddharth : Update Service PO Status';
$data['PO'] = $this->purchaseorder_model->GetServicePOListforStatusUpdate();
$data['WorkStatus']=$this->purchaseorder_model->getStatus(7);
$this->loadViews("statusofservicepurchaseorder", $this->global,$data,Null);
}
function getPODetails()
{
$PONO = $this->input->post('id');
$PO=$PONO;
$result = $this->purchaseorder_model->GetPODetailforBillingServicePO($PO);
$HTML="";
for ($i = 0; $i < count($result); $i++)
{
$SNo = $i + 1;
$ReqNo = $result[$i]['ReqNo'];
$Reqedby = $result[$i]['FirstName'];
$ReqDate = $result[$i]['ReqDate'];
$SupplierID = $result[$i]['SupplierName'];
$Workstatus = $result[$i]['WorkStatus'];
$MaterialCode = $result[$i]['MaterialCode'];
$Description = $result[$i]['ServiceMaterialDescription'];
$UOM = $result[$i]['UOM'];
$Quantity = $result[$i]['Quantity'];
$Rate = $result[$i]['Rate'];
$rdate = new dateTime($result[$i]['ReqDate']);
$ReqDate = $rdate->format('d-m-Y');
$HTML.="<tr id='".$SNo."'>
<td align='left'>".$SNo."</td>
<td align='left'>". $ReqNo."</td>
<td align='left'>".$Reqedby."</td>
<td align='left'>".$ReqDate."</td>
<td align='left'>".$SupplierID."</td>
<td align='left'>".$MaterialCode."</td>
<td align='left' >".$Description."</td>
<td align='left'>".$UOM."</td>
<td align='left'>".$Quantity."</td>
<td align='left'>".$Rate."</td>
<td align='left'>".$Workstatus."</td>
</tr>";
}
echo $HTML;
}
function UpdateServiceStatus()
{
$PONO = $this->input->post('PONO');
$WorkStatus = $this->input->post('WorkStatus');
$Remarks = $this->input->post('Remarks');
$updatedBy = $this->session->userdata ( 'userId' );
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updateddt = $dt->format('Y-m-d H:i:s');
if($WorkStatus== SERVICE_COMPLETED ){
$POStatus=PO_SERVICE_COMPLETED;
$POList = array('UpdateBY'=>$updatedBy,'UpdatedOn'=>$updateddt,'ServiceWorkStatusRemarks'=>$Remarks,'ServiceWorkStatus'=>$WorkStatus,'Status'=>$POStatus);
$PO=$PONO;
$result = $this->purchaseorder_model->GetPODetailforBillingServicePO($PO);
for ($i = 0; $i < count($result); $i++)
{
$MaterialCode = $result[$i]['MaterialCode'];
$ReqList = $this->purchaseorder_model->updateReqDetail($PONO,$POStatus,$MaterialCode);
}
// $ReqList = $this->purchaseorder_model->updateReqDetail($PONO,$POStatus);
$this->purchaseorder_model->UpdateReceivedQtyforServicePO($PONO,$updateddt,$updatedBy);
}
else{
$POList = array('UpdateBY'=>$updatedBy,'UpdatedOn'=>$updateddt,'ServiceWorkStatusRemarks'=>$Remarks,'ServiceWorkStatus'=>$WorkStatus);
}
$POMaster = $this->purchaseorder_model->updatePOMaster($PONO,$POList);
$this->UpdateServicePOStatus();
echo "<script>alert('Successfully Updated the workStatus of the PO ".$PONO."')</script>";
}
// To get the available Budget Amount
function AvilBudgetAmount()
{
// echo 'Controller called';
$this->load->model('costcenter_model');
$CostCode = $this->input->post('id');
$ReqType = $_GET['ReqType'];
$FYStart = '';
$FYEnd = '';
$FiscalYear = $this->costcenter_model->getFiscalYear();
if(!empty($FiscalYear))
{
foreach ($FiscalYear as $Fy)
{
$FYStart =$Fy->StartYear;
$FYEnd =$Fy->EndYear;
}
}
$FYdt = $FYStart." - ".$FYEnd ;
$this->load->model('purchaseorder_model');
$result = array();
if($ReqType== CAPITAL)
{
$result = $this->purchaseorder_model->GetAvailableCapitalBudgetAmount($CostCode,$FYdt,$ReqType);
}
else if($ReqType== IMPORT)
{
$result = $this->purchaseorder_model->GetAvailableImportBudgetAmount($CostCode,$FYdt,$ReqType);
}
else
{
$result = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode,$FYdt,$ReqType);
}
//print_r($result);
$AvilBudAmt = '0';
if(count($result)>0)
{
$AvilBudAmt = $result[0]['BudgetAmount'] - $result[0]['Totalvalue'];
}
// echo 'Test';
print_r($AvilBudAmt);
//die(json_encode(array('Cost' => $AvilBudAmt)));
}
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;
}
//This used to Create Service Purchase Order
function addNewServicePurchaseOrder()
{
$POdt =$this->input->post('PODate');
$PODate = $this->getDateformat($POdt);
$SupplierID = $this->input->post('drpSupplier');
$DeliveryAddr = $this->input->post('DeliveryAddr');
$dt = $this->input->post('Deliverydt');
//$Deliverydt = $this->getDateformat($dt);
$DeliveryOption = $this->input->post('DateRange');
if($DeliveryOption==1)
{
$Deliverydt = '';
$DeliverySchedule = $this->input->post('Scheduleby');
}
else{
$Deliverydt = $this->getDateformat($dt);
$DeliverySchedule = '';
}
$ModeOfShipment=$this->input->post('addmodeofshipment');
$SupplierReference=$this->input->post('addsupplierreference');
$SuppliersOfferNo=$this->input->post('addsupplierofferno');
$OtherReferences=$this->input->post('addotherreference');
$Fincap=$this->input->post('addfincap');
$InsuranceOptions=$this->input->post('insuranceStatus');
$InsuranceNo=$this->input->post('insuranceNo');
$ServiceTypeOptions=$this->input->post('PoTypeOptions');
$DescriptionOfPo = $this->input->post('descofpo');
$PaymentTerms=$this->input->post('PaymentTerms');
$OtherPayment=$this->input->post('Otherpayment');
$POType = $this->input->post('POType');
$SpcialInstruction = $this->input->post('ScopeOfWork');
$TotalOrderValueSummary = $this->input->post('txtTotalOrderValueSummary');
$POStatus = $this->input->post('txtStatus');
$CreateBy = $this->session->userdata ( 'userId' );
$RowCount = $this->input->post('txtRowCount');
$DeletedRow = $this->input->post('txtDeletedRow');
$comma_separated = explode(':', $DeletedRow);
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$createddt = $dt->format('Y-m-d H:i:s');
$WorkStatus=$this->input->post('workstatus');
// PO Master
$POList = array('SupplierID'=>$SupplierID, 'TotalOrderValue'=>$TotalOrderValueSummary,'PODate'=>$PODate,'Status'=>$POStatus, 'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption, 'ServiceDescription'=>$SpcialInstruction,'CreatedBy'=>$CreateBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'CreatedDate'=>$createddt,'PaymentTerms'=>$PaymentTerms,'ServiceWorkStatus'=>$WorkStatus,'POType'=>$POType,'PaymentOtherDescription'=>$OtherPayment,'Supplier_Reference'=>$SupplierReference,'Mode_Of_Shipment'=>$ModeOfShipment,'Supplier_Offer_No'=>$SuppliersOfferNo,'Other_Reference'=>$OtherReferences,'Fincap'=>$Fincap,'Description_Of_Service'=>$DescriptionOfPo,'InsuranceStatus'=>$InsuranceOptions,'InsuranceNumber'=>$InsuranceNo,'POSubType'=>$ServiceTypeOptions);
$POMaster = $this->purchaseorder_model->addPOMaster($POList,$POType,$ServiceTypeOptions);
$PONO = '';
if(count($POMaster)>0)
{
$PONO = $POMaster[0]['PONO'];
}
// PO Line Items
$LineItemStatus = REQITEM_NEW;
for ($i = 1; $i <= $RowCount; $i++)
{
$Per = $this->input->post('per'.$i);
$MaterialCode = $this->input->post('materialCode'.$i);
$Quantity = $this->input->post('quantity'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$itemRate = $this->input->post('itemRate'.$i);
$Cgst = $this->input->post('Cgst'.$i);
$Sgst = $this->input->post('Sgst'.$i);
$Igst = $this->input->post('Igst'.$i);
$AfterCgst = $this->input->post('AfterCgst'.$i);
$AfterSgst = $this->input->post('AfterSgst'.$i);
$AfterIgst = $this->input->post('AfterIgst'.$i);
$CostCenter = $this->input->post('costCode'.$i);
$ServiceFrequency=$this->input->post('Frequency'.$i);
$ItemDescription = $this->input->post('ItemDescription'.$i);
$OtherAmt = $this->input->post('OtherAmt'.$i);
$TotalOrderValue = $this->input->post('TotalOrderValue'.$i);
$SkipInsert = "False";
if( count($comma_separated) > 0)
{
for($j = 1; $j < count($comma_separated); $j++)
{
$deletedRow = $comma_separated[$j] ;
if($deletedRow == $i )
{
$SkipInsert = "True";
break;
}
}
}
if($SkipInsert == "False")
{
$this->load->model('requistion_model');
$RetItemNo = $this->requistion_model->getItemNumber($Reqnumber,$MaterialCode);
$ItemNo = '';
if(count($RetItemNo)>0)
{
$ItemNo = $RetItemNo[0]['ItemNo'];
}
$POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'CostCenterCode'=>$CostCenter,'ServiceFrequency'=>$ServiceFrequency,'ServiceMaterialDescription'=>$ItemDescription,'Per'=>$Per,'ItemNo'=>$ItemNo);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
$LineItemNo = '';
if(count($POLineItem)>0)
{
$LineItemNo = $POLineItem[0]['LineItemNo'];
}
//echo $LineItemNo;
if(trim($POType) == SERVICE )
{
// echo 'Success';
$ServiceTaxList = array('LineItemNo'=>$LineItemNo, 'CGST'=>$Cgst,'After_CGST'=>$AfterCgst,'SGST'=>$Sgst,'After_SGST'=>$AfterSgst,'IGST'=>$Igst,'After_IGST'=>$AfterIgst,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'otherallowance'=>$OtherAmt);
$ServiceTax = $this->purchaseorder_model->addServiceTax($ServiceTaxList);
}
}
}
echo 'Service Purchase Order Created Successfully!The PO NO Is: '.$PONO;
}
//update service po
function UpdateServicePurchaseOrder()
{
$PONO =$this->input->post('txtPONO');
//echo $PONO;
$POdt =$this->input->post('PODate');
$PODate = $this->getDateformat($POdt);
$SupplierID = $this->input->post('drpSupplier');
$DeliveryAddr = $this->input->post('txtDeliveryAddress');
$dt = $this->input->post('Deliverydt');
$DeliveryOption = $this->input->post('DateRange');
if($DeliveryOption==1){
$Deliverydt = '';
$DeliverySchedule = $this->input->post('Scheduleby');
}
else{
$Deliverydt = $this->getDateformat($dt);
$DeliverySchedule = '';
}
$ModeOfShipment=$this->input->post('editmodeofshipment');
$SupplierReference=$this->input->post('editsupplierreference');
$SuppliersOfferNo=$this->input->post('editsupplierofferno');
$OtherReferences=$this->input->post('editotherreference');
$Fincap=$this->input->post('editfincap');
$InsuranceOptions=$this->input->post('insuranceStatus');
$InsuranceNo=$this->input->post('insuranceNo');
$ServiceTypeOptions=$this->input->post('PoTypeOptions');
$DescriptionOfPo = $this->input->post('editdescofpo');
$PaymentTerms=$this->input->post('PaymentTerms');
$OtherPayment=$this->input->post('Otherpayment');
$POType = $this->input->post('POType');
$SpcialInstruction = $this->input->post('ScopeofWork');
$TotalOrderValueSummary = $this->input->post('txtTotalOrderValueSummary');
$POStatus = $this->input->post('txtStatus');
$updatedBy = $this->session->userdata ( 'userId' );
$RowCount = $this->input->post('txtRowCount');
$DeletedRow = $this->input->post('txtDeletedRow');
$comma_separated = explode(':', $DeletedRow);
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updateddt = $dt->format('Y-m-d H:i:s');
$WorkStatus=$this->input->post('workstatus');
// PO Master
$POList = array('SupplierID'=>$SupplierID, 'TotalOrderValue'=>$TotalOrderValueSummary,'PODate'=>$PODate,'Status'=>$POStatus,'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'ServiceDescription'=>$SpcialInstruction,'UpdateBY'=>$updatedBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'UpdatedOn'=>$updateddt,'PaymentTerms'=>$PaymentTerms,'ServiceWorkStatus'=>$WorkStatus,'PaymentOtherDescription'=>$OtherPayment,'Supplier_Reference'=>$SupplierReference,'Mode_Of_Shipment'=>$ModeOfShipment,'Supplier_Offer_No'=>$SuppliersOfferNo,'Other_Reference'=>$OtherReferences,'Fincap'=>$Fincap,'Description_Of_Service'=>$DescriptionOfPo,'InsuranceStatus'=>$InsuranceOptions,'InsuranceNumber'=>$InsuranceNo,'POSubType'=>$ServiceTypeOptions);
$POMaster = $this->purchaseorder_model->updatePOMaster($PONO,$POList);
$LineItemStatus = REQITEM_NEW;
for ($i = 1; $i <= $RowCount; $i++)
{
$MaterialCode = $this->input->post('materialCode'.$i);
$Quantity = $this->input->post('quantity'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$itemRate = $this->input->post('itemRate'.$i);
$Cgst = $this->input->post('Cgst'.$i);
$Sgst = $this->input->post('Sgst'.$i);
$Igst = $this->input->post('Igst'.$i);
$AfterCgst = $this->input->post('AfterCgst'.$i);
$AfterSgst = $this->input->post('AfterSgst'.$i);
$AfterIgst = $this->input->post('AfterIgst'.$i);
$CostCenter = $this->input->post('costCode'.$i);
$ServiceFrequency=$this->input->post('Frequency'.$i);
$POLineItemNo = $this->input->post('LineItemNo'.$i);
$TotalOrderValue = $this->input->post('TotalOrderValue'.$i);
$ItemDescription = $this->input->post('ItemDescription'.$i);
$OtherAmt = $this->input->post('OtherAmt'.$i);
$Per = $this->input->post('per'.$i);
$POLineItem = array();
$LineItemNo = '';
$SkipInsert = "False";
if( count($comma_separated) > 0)
{
for($j = 1; $j < count($comma_separated); $j++)
{
$deletedRow = $comma_separated[$j] ;
if($deletedRow == $i )
{
$SkipInsert = "True";
break;
}
}
}
if($SkipInsert == "False")
{
if(strlen($POLineItemNo) == 0)
{
$this->load->model('requistion_model');
$RetItemNo = $this->requistion_model->getItemNumber($Reqnumber,$MaterialCode);
$ItemNo = '';
if(count($RetItemNo)>0)
{
$ItemNo = $RetItemNo[0]['ItemNo'];
}
$POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt,'CostCenterCode'=>$CostCenter,'ServiceFrequency'=>$ServiceFrequency,'ServiceMaterialDescription'=>$ItemDescription,'Per'=>$Per,'ItemNo'=>$ItemNo);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
if(count($POLineItem)>0)
{
$LineItemNo = $POLineItem[0]['LineItemNo'];
}
}
else
{
$LineItemNo = $POLineItemNo;
$POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'UpdateBY'=>$updatedBy,'UpdatedOn'=>$updateddt,'CostCenterCode'=>$CostCenter,'ServiceMaterialDescription'=>$ItemDescription,'Per'=>$Per);
$POLineItem = $this->purchaseorder_model->updatePOLineItem($PONO,$POLineItemNo,$POLineItemList);
}
if(trim($POType) == SERVICE )
{
$isExists = $this->purchaseorder_model->LineItemExists($LineItemNo);
if(count($isExists) == 0)
{
$ServiceTaxList = array('LineItemNo'=>$LineItemNo, 'CGST'=>$Cgst,'After_CGST'=>$AfterCgst,'SGST'=>$Sgst,'After_SGST'=>$AfterSgst,'IGST'=>$Igst,'After_IGST'=>$AfterIgst,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt,'otherallowance'=>$OtherAmt);
$this->purchaseorder_model->addServiceTax($ServiceTaxList);
}
else
{
$ServiceTaxList1 = array('CGST'=>$Cgst,'After_CGST'=>$AfterCgst,'SGST'=>$Sgst,'After_SGST'=>$AfterSgst,'IGST'=>$Igst,'After_IGST'=>$AfterIgst,'TotalValue'=>$TotalOrderValue, 'UpdateBY'=>$updatedBy,'UpdatedOn'=>$updateddt,'otherallowance'=>$OtherAmt);
$this->purchaseorder_model->updateServiceTax($LineItemNo,$ServiceTaxList1);
}
}
}
}
echo 'Purchase Order Updated Successfully! PO Number Is: '.$PONO;
}
function pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}
?>