ria/application/controllers/amendmentpurchaseorder.php
venbatechnologies@gmail.com b1c8fe52a4 issues fixes
2018-07-12 12:34:06 +05:30

1527 lines
68 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : Amendment Purchase Order controller
* amendmentpurchaseorder Class to control all amendmented po's related operations.
* @author : Venba Info Tech - Velmurugan
* @version : 1.1
* @since : 18 November 2017
*/
class amendmentpurchaseorder extends BaseController
{
/**
* 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->isLoggedIn();
$this->CompanyName = $this->global['CompanyName'];
}
/**
* Index Page for this controller(default function of the class)
*/
public function index()
{
$this->load->library('pagination');
$forwhat='amendment';
$data['POData'] = $this->purchaseorder_model->purchaseorderListing($forwhat);
//$this->global['pageTitle'] = 'Resico : Amendment Purchase Order';
$this->global['pageTitle'] = $this->CompanyName.' : Amendment Purchase Order';
$this->loadviews('AmendPOlist',$this->global,$data,NULL);
}
/**
* For editing purpose and it has oldest all released po.
*/
function EditAmendPurchaseOrder()
{
$PONO = $_GET['PONO'];
$ReqType = $_GET['ReqType'];
$Req = $this->purchaseorder_model->getRequistionNoFromPO($PONO);
$data['ReqList'] = $Req ;
$result = array();
$ReqArray = array();
$Status = '';
foreach ($Req as $SID):
$ReqArray[] = $SID->ReqNo ;
$result[] = $this->purchaseorder_model->getRawPOMaterialList($SID->ReqNo);
endforeach;
$data['MaterialList'] = $result;
$data['Suplist'] = $this->purchaseorder_model->getSupplierName();
$data['Payment']=$this->purchaseorder_model->getPaymentTermsDetails();
$data['INRSYMBOL']=$this->purchaseorder_model->GetINRCurrencytype('INR');
/* Cost code from Requisition - Client Review Fix
Start here */
$ReqDetails = $this->purchaseorder_model->getRequistDetails($ReqArray);
$data['RequistionDetails'] = $ReqDetails;
foreach ($data['RequistionDetails'] as $ReqDet)
{
$Status=$ReqDet->Status;
}
$data['POSTATUS']=$this->purchaseorder_model->GetPOStatus($Status);
foreach ($data['POSTATUS'] as $POST)
{
$Status=$POST->StatusName;
}
$CostCode = '';
$this->load->model('costcenter_model');
$FYStart = '';
$FYEnd = '';
$FiscalYear = $this->costcenter_model->getFiscalYear();
if(!empty($FiscalYear))
{
foreach ($FiscalYear as $Fy)
{
$FYStart =$Fy->StartYear;
$FYEnd =$Fy->EndYear;
}
}
$FYdt = $FYStart." - ".$FYEnd ;
foreach ($ReqDetails as $Rs):
$CostCode = $Rs->CostCenterCode;
endforeach;
$AvlBudget = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode,$FYdt,$ReqType);
if(count($AvlBudget)>0)
{
$data['AvlBudAmt'] = $AvlBudget[0]['BudgetAmount'] - $AvlBudget[0]['Totalvalue'];
}
/* End Here */
$data['POMaster'] = $this->purchaseorder_model->GetServicePurchaseOrder($PONO);
$data['MaxPODate'] = $this->purchaseorder_model->getLastCreatedPODate();
$data['TaxType'] = $this->purchaseorder_model->getConfigValue('C006');
$data['FreightType'] = $this->purchaseorder_model->getConfigValue('C018');
$data['PoTypeOptions'] = $this->purchaseorder_model->getConfigValue('C026');
if($ReqType == SERVICE)
{
$data['POItem'] = $this->purchaseorder_model->GetServicePurchaseOrderDetails($PONO);
$data['PaymentTerms']=$this->purchaseorder_model->GetPaymentTerms($PONO);
$data['WorkStatus']=$this->purchaseorder_model->getStatus(7);
//$this->global['pageTitle'] = 'Resico : Edit Service Purchase order form';
$this->global['pageTitle'] = $this->CompanyName.' : Amendment Service Purchase Order';
$this->loadViews("editServiceAmendPO", $this->global, $data, NULL);
}
else if($ReqType == REVENUE)
{
$data['POSTATUS']=$this->purchaseorder_model->GetPOStatus($PONO);
$data['POItem'] = $this->purchaseorder_model->GetRevenuePurchaseOrderDetails($PONO);
$data['PaymentTerms']=$this->purchaseorder_model->GetPaymentTerms($PONO);
//$this->global['pageTitle'] = 'Resico : Edit Revenue Purchase order form';
$this->global['pageTitle'] = $this->CompanyName.' : Amendment Revenue Purchase Order';
$this->loadViews("editRevenueAmendPO", $this->global, $data, NULL);
}
else if($ReqType == IMPORT)
{
$AvlBudget = $this->purchaseorder_model->GetAvailableImportBudgetAmount($CostCode,$FYdt,$ReqType);
if(count($AvlBudget)>0)
{
$data['AvlBudAmt'] = $AvlBudget[0]['BudgetAmount'] - $AvlBudget[0]['Totalvalue'];
}
$data['POItem'] = $this->purchaseorder_model->GetImportPurchaseOrderDetails($PONO);
$data['Currency']=$this->purchaseorder_model->GetCurrencytype();
$data['PoTypeOptions'] = $this->purchaseorder_model->getConfigValue('C026');
foreach($data['POMaster'] as $CUR)
{
$Currency=$CUR->CurrencyType;
}
$data['CurrencyDetail']=$this->purchaseorder_model->GetCurrencyDetail($Currency);
$data['PaymentTerms']=$this->purchaseorder_model->GetPaymentTerms($PONO);
$data['INRSYMBOL']=$this->purchaseorder_model->GetINRCurrencytype('INR');
$unicode ='';
foreach ($data['CurrencyDetail'] as $Detail)
{
$unicode=$Detail->FontCode2000;
}
foreach ($data['CurrencyDetail'] as $Detail)
{
$currencycode=$Detail->Currency_Code;
}
$data['unicode']=$unicode;
$data['currencycode']=$currencycode;
//$this->global['pageTitle'] = 'Resico : Edit Import Purchase order form';
$this->global['pageTitle'] = $this->CompanyName.' : Amendment Import Purchase Order';
$this->loadViews("editImportAmendPO", $this->global, $data, NULL);
}
else if($ReqType == CAPITAL)
{
$CapitalRange = $_GET['CapitalRange'];
$CapitalAvlBudget = $this->purchaseorder_model->GetAvailableCapitalBudgetAmount($CostCode,$FYdt,$ReqType);
if(count($CapitalAvlBudget)>0)
{
$data['AvlCapitalBudAmt'] = $CapitalAvlBudget[0]['BudgetAmount'] - $CapitalAvlBudget[0]['Totalvalue'];
}
if($CapitalRange=='0'){
$data['POItem'] = $this->purchaseorder_model->getCapitalPurchaseOrderDetails($PONO);
}
else if($CapitalRange=='1'){
$data['POItem'] = $this->purchaseorder_model->getDomesticCapitalPurchaseOrderDetails($PONO);
}
$data['requestedBy'] = $this->purchaseorder_model->GetRequesedByDetails($PONO);
$CapitalRange='';
foreach($data['POItem'] as $Rate)
{
$exRate=$Rate->ExchangeRate;
$CapitalRange=$Rate->CapitalRange;
}
foreach($data['POItem'] as $CUR)
{
$Currency=$CUR->CurrencyType;
}
if($CapitalRange=='0'){
$data['CurrencyDetail']=$this->purchaseorder_model->GetCurrencyDetail($Currency);
$data['ExchangeRate']=$exRate;
$data['Currency']=$this->purchaseorder_model->GetCurrencytype();
}
else if($CapitalRange=='1'){
$data['CurrencyDetail']='';
$data['ExchangeRate']=$exRate;
$data['Currency']=$this->purchaseorder_model->GetCurrencytype();
}
//$this->global['pageTitle'] = 'Resico : Edit Capital Purchase order form';
$this->global['pageTitle'] = $this->CompanyName.' : Amendment Capital Purchase Order';
$this->loadViews("editCapitalAmendPO", $this->global, $data, NULL);
}
}
/**
* To Store release Revenue Po values after edit
*/
function EditRevenuePurchaseOrder()
{
$NewPO='';
$MAD='';
$PONO =$this->input->post('txtPONO');
$POdt =$this->input->post('PODate');
$PODate = $this->getDateformat($POdt);
$SupplierID = $this->input->post('drpSupplier');
$POType = $this->input->post('POType');
$DeliveryAddr = $this->input->post('txtDeliveryAddress');
$dt = $this->input->post('Deliverydt');
$predeliverydate=$this->input->post('beforeDeliverydt');
$preschedule=$this->input->post('beforeScheduleby');
$DeliverySchedule1 = $this->input->post('Scheduleby');
$DeliveryOption = $this->input->post('DateRange');
if($DeliveryOption==1){
$Deliverydt=null;
$DeliverySchedule = $this->input->post('Scheduleby');
}
else{
$Deliverydt = $this->getDateformat($dt);
$DeliverySchedule = '';
}
$Modeofshipment=$this->input->post('addmodeofshipment');
$supplierreference=$this->input->post('amendsupplierreference');
$supplieroffno=$this->input->post('amendsupplierofferno');
$otherreference=$this->input->post('amendotherreference');
$fincap=$this->input->post('amendfincap');
$revenuetype=$this->input->post('PoTypeOptions');
$insurancestatus=$this->input->post('insurancestatus');
if($insurancestatus == 1){
$insuranceno=$this->input->post('insuranceno');
}else{
$insuranceno="";
}
$POType = $this->input->post('POType');
$PoRange = $this->input->post('Range');
$PaymentTermsText=$this->input->post('beforePaymentTermsText');
$PaymentTerms=$this->input->post('PaymentTerms');
$Otherpayment=$this->input->post('Otherpayment');
$Otherpaymentamend=$this->input->post('Otherpayment');
$prePaymentTerms=$this->input->post('beforePaymentTerms');
$preTotalOdervalue=$this->input->post('preTotalOdervalue');
$MAD.="Current TotalOrder Value:&nbsp;&nbsp;:" . $preTotalOdervalue ."<br>";
$testdate=date("Y-m-d");
if($PaymentTerms!=$prePaymentTerms)
{
if($prePaymentTerms != 'PT08'){ $Otherpaymentamend='';}
$MAD.="Current PaymentTerms :&nbsp;&nbsp;". $PaymentTermsText . $Otherpaymentamend ."<br>";
}
if(($dt != $predeliverydate)|| ($DeliverySchedule1 != $preschedule))
{
$MAD.='Current Delivery Option : &nbsp;&nbsp; ' . $predeliverydate . $preschedule . '<br>' ;
}
$SpecialInstruction = $this->input->post('txtSpcialInstruction');
$TotalOrderValueSummary = $this->input->post('txtTotalOrderValueSummary');
$POStatus = $this->input->post('txtStatus');
$updatedBy = $this->session->userdata ( 'userId' );
$RowCount = $this->input->post('txtRowCount');
$dtt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updateddt = $dtt->format('Y-m-d H:i:s');
$qtycheck = $this->purchaseorder_model->getqtycheck($PONO);
$qtycheckresult='';
foreach($qtycheck as $qty)
{
$qtycheckresult= $qty->IsQualityChkReqired;
}
if(empty($Deliverydt))
{
$Deliverydt=null;
}
if($PaymentTerms != 'PT08'){
$Otherpayment='';
}
$POMaster = array('ParentPO'=>$PONO,'SupplierID'=>$SupplierID,'POType'=>$POType,'PORange'=>$PoRange,'TotalOrderValue'=>$TotalOrderValueSummary,'PODate'=>$PODate,'Status'=>PO_RELEASED,'PaymentTerms'=>$PaymentTerms,'PaymentOtherDescription'=>$Otherpayment,'Mode_Of_Shipment'=>$Modeofshipment,'Supplier_Reference'=>$supplierreference,'Supplier_Offer_No'=>$supplieroffno,'Other_Reference'=>$otherreference,'Fincap'=>$fincap,'InsuranceStatus'=>$insurancestatus,'InsuranceNumber'=>$insuranceno,'POSubType'=>$revenuetype,'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'ServiceDescription'=>$SpecialInstruction,'CreatedBy'=>$updatedBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'UpdatedOn'=>$updateddt,'ReleasedBy'=>$updatedBy,'ReleasedOn'=>$updateddt,'AmendedDetails'=>$MAD,'IsQualityChkReqired'=>$qtycheckresult);
$LastPO = $this->purchaseorder_model->addAmendPOMaster($POMaster,$updatedBy,$PONO);
if(count($LastPO)>0)
{
$NewPO = $LastPO[0]['PONO'];
}
$PODetail=array('Status'=>PO_AMENDED);//TO SET PARENT PO AS AMENDMENT STATUS
$APO=$this->purchaseorder_model->updateAmendPOMaster($PONO,$PODetail);
$LineItemStatus = REQITEM_NEW;
$igrvalue = $this->purchaseorder_model->selectigrmaster($PONO);
$po = '';
$igrno ='';
foreach ($igrvalue as $value) {
$igrno = $value->IGRNO;
$po =$value->PONO;
if($PONO == $po)
{
$NewPOno = array('PONO' =>$NewPO);
$this->purchaseorder_model->updateigrmaster($igrno,$NewPOno);
}
}
for ($i = 1; $i <= $RowCount; $i++)
{
$CAD='';
$MaterialCode = $this->input->post('materialCode'.$i);
$Quantity = $this->input->post('quantity'.$i);
$preqty=$this->input->post('beforeqty'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$itemRate = $this->input->post('itemRate'.$i);
$preitemrate=$this->input->post('beforeitemRate'.$i);
$per=$this->input->post('per'.$i);
$servicematerialdescription=$this->input->post('service_description'.$i);
$DiscountType = $this->input->post('DisType'.$i);
$beforeDiscountType = $this->input->post('beforeDisType'.$i);
$DiscountValue = $this->input->post('DisVal'.$i);
$preDiscountValue = $this->input->post('beforeDisVal'.$i);
$AfterDiscount = $this->input->post('AfterDisVal'.$i);
$beforeAfterDiscount = $this->input->post('beforeAfterDisVal'.$i);
$PackagingOption = $this->input->post('PackOption'.$i);
$PackagingType = $this->input->post('PackType'.$i);
$beforePackagingType = $this->input->post('beforePackType'.$i);
$PackagingValue = $this->input->post('PackVal'.$i);
$prePackagingValue = $this->input->post('beforePackVal'.$i);
$AfterPackagingValue = $this->input->post('AfterPackVal'.$i);
$beforeAfterPackagingValue = $this->input->post('beforeAfterPackVal'.$i);
$VatValue = $this->input->post('VatVal'.$i);//SGST
$preVatValue = $this->input->post('beforeVatVal'.$i);
$AfterVatValue = $this->input->post('AfterVatVal'.$i);
$beforeAfterVatValue = $this->input->post('beforeAfterVatVal'.$i);
$GSTValue = $this->input->post('GSTVal'.$i);//CGST
$preGSTValue = $this->input->post('beforeGSTVal'.$i);
$AfterGSTValue = $this->input->post('AfterGSTVal'.$i);
$beforeAfterGSTValue = $this->input->post('beforeAfterGSTVal'.$i);
$OtherTaxValue = $this->input->post('OtherTaxVal'.$i);//IGST
$preOtherTaxValue = $this->input->post('beforeOtherTaxVal'.$i);
$AfterOtherTaxValue = $this->input->post('AfterOtherTaxVal'.$i);
$beforeAfterOtherTaxValue = $this->input->post('beforeAfterOtherTaxVal'.$i);
$FreightType = $this->input->post('FreightType'.$i);
$beforeFreightType = $this->input->post('beforeFreightType'.$i);
$FreightValue = $this->input->post('FreightVal'.$i);
$preFreightValue = $this->input->post('beforeFreightVal'.$i);
$AfterFreightValue = $this->input->post('AfterFreightVal'.$i);
$beforeAfterFreightValue = $this->input->post('beforeAfterFreightVal'.$i);
$NoofTrips = $this->input->post('Nooftrips'.$i);
$beforeNoofTrips = $this->input->post('beforeNooftrips'.$i);
$InsuranceValue = $this->input->post('Insval'.$i);
$preInsuranceValue = $this->input->post('beforeInsval'.$i);
$TotalOrderValue = $this->input->post('TotalOrderValue'.$i);
$POLineItemNo = $this->input->post('LineItemNo'.$i);
$CostCenter = $this->input->post('costCode'.$i);
$ServiceFrequency=$this->input->post('Frequency'.$i);
$LineItemNo = '';
$RecQtyvalue=0;
$rowspanvalue=0;
if(($Quantity-$preqty)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Quantity : ".$preqty ."</td><td>Revised Qty : ".$Quantity."</td></tr>";
}
if(($itemRate-$preitemrate)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Rate : " . $preitemrate."</td><td>Revised Item Rate : ".$itemRate."</td></tr>";
}
if($DiscountType != $beforeDiscountType){
$rowspanvalue++;
$CAD.="<tr><td>Current DiscountType : " . $beforeDiscountType."</td><td>Revised DiscountType : ".$DiscountType."</td></tr>";
}
if(($DiscountValue-$preDiscountValue)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Discount : ". $preDiscountValue ."</td><td>Revised Discount : ".$DiscountValue."</td></tr>";
}
if(($AfterDiscount-$beforeAfterDiscount)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Discount Value : ". $beforeAfterDiscount ."</td><td>Revised Discount Value : ".$AfterDiscount."</td></tr>";
}
if($PackagingType != $beforePackagingType){
$rowspanvalue++;
$CAD.="<tr><td>Current Packaging Type : ". $beforePackagingType ."</td><td>Revised Packaging Type : ".$PackagingType."</td></tr>";
}
if(($PackagingValue-$prePackagingValue)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Package Value : ". $prePackagingValue."</td><td>Revised Package Value : ".$PackagingValue."</td></tr>";
}
if(($AfterPackagingValue-$beforeAfterPackagingValue)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Package Value : ". $beforeAfterPackagingValue."</td><td>Revised Package Value : ".$AfterPackagingValue."</td></tr>";
}
if(($VatValue-$preVatValue)!=0)//SGST
{
$rowspanvalue++;
$CAD.="<tr><td>Current SGST : ". $preVatValue."</td><td>Revised SGST : ".$VatValue."</td></tr>";
}
if(($AfterVatValue-$beforeAfterVatValue)!=0)//SGST
{
$rowspanvalue++;
$CAD.="<tr><td>Current SGST value : ". $beforeAfterVatValue."</td><td>Revised SGST Value : ".$AfterVatValue."</td></tr>";
}
if(($GSTValue-$preGSTValue)!=0)//CGST
{
$rowspanvalue++;
$CAD.="<tr><td>Current CGST : ". $preGSTValue."</td><td>Revised CGST : ".$GSTValue."</td></tr>";
}
if(($AfterGSTValue-$beforeAfterGSTValue)!=0)//CGST
{
$rowspanvalue++;
$CAD.="<tr><td>Current CGST Value : ". $beforeAfterGSTValue."</td><td>Revised CGST Value : ".$AfterGSTValue."</td></tr>";
}
if(($OtherTaxValue-$preOtherTaxValue)!=0)//IGST
{
$rowspanvalue++;
$CAD.="<tr><td>Current IGST : ". $preOtherTaxValue."</td><td>Revised IGST : ".$OtherTaxValue."</td></tr>";
}
if(($AfterOtherTaxValue-$beforeAfterOtherTaxValue)!=0)//IGST
{
$rowspanvalue++;
$CAD.="<tr><td>Current IGST : ". $beforeAfterOtherTaxValue."</td><td>Revised IGST : ".$AfterOtherTaxValue."</td></tr>";
}
if($FreightType != $beforeFreightType){
$rowspanvalue++;
$CAD.="<tr><td>Current Freight Type : ". $beforeFreightType."</td><td>Revised Freight Type : ".$FreightType."</td></tr>";
}
if(($FreightType=="PER TRIP") || ($beforeFreightType=="PER TRIP")){
if($NoofTrips != $beforeNoofTrips)
{
$rowspanvalue++;
$CAD.="<tr><td>Current No of Trips : ". $beforeNoofTrips."</td><td>Revised No of Trips : ".$NoofTrips."</td></tr>";
}
}
if(($FreightValue-$preFreightValue)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Freight : ". $preFreightValue."</td><td>Revised Freight : ".$FreightValue."</td></tr>";
}
if(($AfterFreightValue-$beforeAfterFreightValue)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Freight Value : ". $beforeAfterFreightValue."</td><td>Revised Freight Value : ".$AfterFreightValue."</td></tr>";
}
if(($InsuranceValue-$preInsuranceValue)!=0)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Insurance Value : ". $preInsuranceValue."</td><td>Revised Insurance Value : ".$InsuranceValue."</td></tr>";
}
if($rowspanvalue>0)
{
$rowspanvalue++;
$CAD2='';
$CAD2=$CAD;
$CAD='';
$CAD="<tr><td rowspan=". $rowspanvalue .">".$MaterialCode."</td></tr>";
$CAD.=$CAD2;
}
$ReceivedQty = $this->purchaseorder_model->GetLineItemReceivedQty($PONO,$MaterialCode);
if(count($ReceivedQty)>0)
{
$RecQtyvalue = $ReceivedQty[0]['ReceivedQuantity'];
}
$POLineItemList = array('PONO'=>$NewPO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'ReceivedQuantity'=>$RecQtyvalue,'Quantity'=>$Quantity,'Per'=>$per,'ServiceMaterialDescription'=>$servicematerialdescription,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt,'CostCenterCode'=>$CostCenter,'ServiceFrequency'=>$ServiceFrequency,'AmendedDetails'=>$CAD);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
if(count($POLineItem)>0)
{
$LineItemNo = $POLineItem[0]['LineItemNo'];
}
$RevenueTaxList = array('LineItemNo'=>$LineItemNo, 'DiscountType'=>$DiscountType,'DiscountValue'=>$DiscountValue,'AfterDiscount'=>$AfterDiscount,'PackagingType'=>$PackagingType,'PackagingValue'=>$PackagingValue,'PackagingCalulatedOn'=>$PackagingOption,'AfterPackagingValue'=>$AfterPackagingValue,'FreightType'=>$FreightType,'NoOfTrip'=>$NoofTrips,'FreightValue'=>$FreightValue,'AfterFreightValue'=>$AfterFreightValue,'SGST'=>$VatValue,'AfterSGST'=>$AfterVatValue,'CGST'=>$GSTValue,'AfterCGST'=>$AfterGSTValue,'IGST'=>$OtherTaxValue,'AfterIGST'=>$AfterOtherTaxValue,'Insurance'=>$InsuranceValue,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt);
$RevenueList = $this->purchaseorder_model->addRevenueTax($RevenueTaxList);
}
$ordqty ='';
$recqty ='';
$qty = $this->purchaseorder_model->getpolineqty($NewPO);
$ordqty = $qty[0]->Qty;
$recqty = $qty[0]->rec;
if($ordqty == $recqty)
{
$Newstatus = array('Status'=>IGR_CREATED);
$this->purchaseorder_model-> POLineItemsupdatestatus($NewPO,$Newstatus);
$Newstat = array('Status'=>IGR_CREATED);
$this->purchaseorder_model->pomasterupdatestatus($NewPO,$Newstat);
}
echo 'Purchase Order Amended Successfully! PO Number Is: '.$PONO .'- New PO Number is'.$NewPO;
}
/**
* To Store release Service Po values after edit
*/
function UpdateAmendServicePurchaseOrder()
{
$PONO =$this->input->post('txtPONO');
$MAD='';
$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 =null;
$DeliverySchedule = $this->input->post('Scheduleby');
}
else{
$Deliverydt = $this->getDateformat($dt);
$DeliverySchedule = '';
}
$ddate=$this->input->post('Deliverydt');
$beforeddate=$this->input->post('beforeDeliverydt');
$testdate=date("Y-m-d");
$dschedule=$this->input->post('Scheduleby');
$beforedschedule=$this->input->post('beforeScheduleby');
$preTotalordervalue=$this->input->post('preTotalordervalue');
$MAD.="Current TotalOrder Value:&nbsp;&nbsp;" . $preTotalordervalue . "<br>";
if(($ddate != $beforeddate)||($dschedule != $beforedschedule))
{
$MAD.="Current DeliveryOption :&nbsp;&nbsp;" . $beforeddate . $beforedschedule."<br>";
}
$PaymentTermsText=$this->input->post('beforePaymentTermsText');
$PaymentTerms=$this->input->post('PaymentTerms');
$Otherpayment=$this->input->post('Otherpayment');
$Otherpaymentamend=$this->input->post('Otherpayment');
$beforePaymentTerms=$this->input->post('beforePaymentTerms');
if($PaymentTerms != $beforePaymentTerms)
{
if($beforePaymentTerms != 'PT08'){ $Otherpaymentamend='';}
$MAD.="Current PaymentTerms :&nbsp;&nbsp;". $PaymentTermsText . $Otherpaymentamend."<br>";
}
$POType = $this->input->post('POType');
$ModeOfShipment=$this->input->post('addmodeofshipment');
$SupplierReference=$this->input->post('amendsupplierreference');
$SuppliersOfferNo=$this->input->post('amendsupplierofferno');
$OtherReferences=$this->input->post('amendotherreference');
$Fincap=$this->input->post('amendfincap');
$InsuranceOptions=$this->input->post('insuranceStatus');
$InsuranceNo=$this->input->post('insuranceNo');
$ServiceTypeOptions=$this->input->post('PoTypeOptions');
$DescriptionOfPo = $this->input->post('amenddescofpo');
$scopeofwork = $this->input->post('ScopeofWork');
$TotalOrderValueSummary = $this->input->post('txtTotalOrderValueSummary');
$POStatus = $this->input->post('txtStatus');
$updatedBy = $this->session->userdata ( 'userId' );
$RowCount = $this->input->post('txtRowCount');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updateddt = $dt->format('Y-m-d H:i:s');
$WorkStatus=$this->input->post('workstatus');
$qtycheck = $this->purchaseorder_model->getqtycheck($PONO);
$qtycheckresult='';
foreach($qtycheck as $qty)
{
$qtycheckresult= $qty->IsQualityChkReqired;
}
// PO Master
if(empty($Deliverydt))
{
$Deliverydt=null;
}
if($PaymentTerms != 'PT08'){
$Otherpayment='';
}
$POMaster = array('ParentPO'=>$PONO,'POType'=>$POType,'SupplierID'=>$SupplierID, 'TotalOrderValue'=>$TotalOrderValueSummary,'PODate'=>$PODate,'Status'=>PO_RELEASED,'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'ServiceDescription'=>$scopeofwork,'CreatedBy'=>$updatedBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'CreatedDate'=>$updateddt,'PaymentTerms'=>$PaymentTerms,'PaymentOtherDescription'=>$Otherpayment,'ServiceWorkStatus'=>$WorkStatus,'ReleasedBy'=>$updatedBy,'ReleasedOn'=>$updateddt,'AmendedDetails'=>$MAD,'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,'IsQualityChkReqired'=>$qtycheckresult);
$LastPO = $this->purchaseorder_model->addAmendPOMaster($POMaster,$updatedBy,$PONO);
$NewPO = '';
if(count($LastPO)>0)
{
$NewPO = $LastPO[0]['PONO'];
}
$PODetail=array('Status'=>PO_AMENDED);//TO SET PARENT PO AS AMENDMENT STATUS
$APO=$this->purchaseorder_model->updateAmendPOMaster($PONO,$PODetail);
$LineItemStatus = REQITEM_NEW;
for ($i = 1; $i <= $RowCount; $i++)
{
$CAD='';
$MaterialCode = $this->input->post('materialCode'.$i);
$MaterialName=$this->input->post('materialName'.$i);
$Quantity = $this->input->post('quantity'.$i);
$beforeQuantity = $this->input->post('beforequantity'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$itemRate = $this->input->post('itemRate'.$i);
$beforeitemRate = $this->input->post('beforeitemRate'.$i);
$Per = $this->input->post('per'.$i);
$AfterSGST = $this->input->post('AfterSgst'.$i);
$beforeSGSTvalue = $this->input->post('beforeSgstvalue'.$i);
$AfterCGST = $this->input->post('AfterCgst'.$i);
$beforeCGSTvalue = $this->input->post('beforeCgstvalue'.$i);
$AfterIGST = $this->input->post('AfterIgst'.$i);
$beforeIGSTvalue = $this->input->post('beforeIgstvalue'.$i);
$SGST = $this->input->post('Sgst'.$i);
$beforeSGST = $this->input->post('beforeSgst'.$i);
$CGST = $this->input->post('Cgst'.$i);
$beforeCGST = $this->input->post('beforeCgst'.$i);
$IGST = $this->input->post('Igst'.$i);
$beforeIGST = $this->input->post('beforeIgst'.$i);
$otherallowance = $this->input->post('otherallowance'.$i);
$beforeotherallowance = $this->input->post('beforeotherallowance'.$i);
$servicematerialdescription = $this->input->post('servicematerialdescription'.$i);
$CostCenter = $this->input->post('costCode'.$i);
$POLineItemNo = $this->input->post('LineItemNo'.$i);
$TotalOrderValue = $this->input->post('TotalOrderValue'.$i);
$ServiceFrequency=$this->input->post('Frequency'.$i);
$LineItemNo = '';
$RecQtyvalue=0;
$rowspanvalue=0;
$ReceivedQty = $this->purchaseorder_model->GetLineItemReceivedQty($PONO,$MaterialCode);
if(count($ReceivedQty)>0)
{
$RecQtyvalue = $ReceivedQty[0]['ReceivedQuantity'];
}
if($Quantity != $beforeQuantity)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Qty :&nbsp;" . $beforeQuantity ."</td><td>Revised Qty :&nbsp;" . $Quantity . "</td></tr>";
}
if($itemRate != $beforeitemRate)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Rate :&nbsp;" . $beforeitemRate ."</td><td>Revised Rate :&nbsp;" . $itemRate . "</td></tr>";
}
if(($SGST != $beforeSGST) && ($AfterSGST != $beforeSGSTvalue))
{
$rowspanvalue+=2;
$CAD.="<tr><td>Current SGST% :&nbsp;" . $beforeSGST ."</td><td>Revised SGST% :&nbsp;" . $SGST . "</td></tr><tr><td>Current SGST value :&nbsp;" . $beforeSGSTvalue ."</td><td>Revised SGST value:&nbsp;" . $AfterSGST . "</td></tr>";
}
if(($CGST != $beforeCGST) && ($AfterCGST != $beforeCGSTvalue))
{
$rowspanvalue+=2;
$CAD.="<tr><td>Current CGST% :&nbsp;" . $beforeCGST ."</td><td>Revised CGST% :&nbsp;" . $CGST . "</td></tr><tr><td>Current CGST value :&nbsp;" . $beforeCGSTvalue ."</td><td>Revised CGST value:&nbsp;" . $AfterCGST . "</td></tr>";
}
if(($IGST != $beforeIGST) && ($AfterIGST != $beforeIGSTvalue))
{
$rowspanvalue+=2;
$CAD.="<tr><td>Current IGST% :&nbsp;" . $beforeIGST ."</td><td>Revised IGST% :&nbsp;" . $IGST . "</td></tr><tr><td>Current IGST value :&nbsp;" . $beforeIGSTvalue ."</td><td>Revised IGST value:&nbsp;" . $AfterIGST . "</td></tr>";
}
if($otherallowance != $beforeotherallowance)
{
$rowspanvalue++;
$CAD.="<tr><td>Current OtherAllowances :&nbsp;" . $beforeotherallowance ."</td><td>Revised OtherAllowances :&nbsp;" . $otherallowance . "</td></tr>";
}
if($rowspanvalue>0)
{
$rowspanvalue++;
$CAD2='';
$CAD2=$CAD;
$CAD='';
$CAD="<tr><td rowspan=". $rowspanvalue .">".$MaterialCode."-".$MaterialName."</td></tr>";
$CAD.=$CAD2;
}
$POLineItemList = array('PONO'=>$NewPO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'ServiceMaterialDescription'=>$servicematerialdescription,'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt,'CostCenterCode'=>$CostCenter,'ServiceFrequency'=>$ServiceFrequency,'ReceivedQuantity'=>$RecQtyvalue,'AmendedDetails'=>$CAD,'Per'=>$Per);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
if(count($POLineItem)>0)
{
$LineItemNo = $POLineItem[0]['LineItemNo'];
}
$ServiceTaxList = array('LineItemNo'=>$LineItemNo,'CGST'=>$CGST,'After_CGST'=>$AfterCGST,'SGST'=>$SGST,'After_SGST'=>$AfterSGST,'IGST'=>$IGST,'After_IGST'=>$AfterIGST,'otherallowance'=>$otherallowance, 'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt);
$ServiceList =$this->purchaseorder_model->addServiceTax($ServiceTaxList);
}
echo 'PO Number is'.$PONO . ' is Amended Successfully! - New Amended PO Number is '.$NewPO;
}
/**
* To Store Capital Po values after edit
*/
function EditAmendCapitalPurchaseOrder()
{
$PONO =$this->input->post('txtPONO');
$MAD='';
$DeliverySchedule = '';
$POdt =$this->input->post('PODate');
$PODate = $this->getDateformat($POdt);
$SupplierID = $this->input->post('drpSupplier');
$DeliveryAddr = $this->input->post('DeliveryAddr');
$dt = $this->input->post('Deliverydate');
$POType = $this->input->post('POType');
$PoRange = $this->input->post('capitalType');
$DeliveryOption = $this->input->post('DateRange');
$Deliverydt = '';
if(($DeliveryOption==1)||($DeliveryOption==2)){
$Deliverydt = null;
if($DeliveryOption==1){
$DeliverySchedule = $this->input->post('Scheduleby');}
}
else{
$Deliverydt = $this->getDateformat($dt);
$DeliverySchedule = '';
}
$predispatch=$this->input->post('beforeDisins');
$curdispatch=$this->input->post('Dispatch');
$PaymentMethod = $this->input->post('PaymentMethod');
$prePaymentmethod=$this->input->post('beforePaymentmethod');
$prePaymentmethodtext=$this->input->post('beforePaymentTermsText');
$DeliverySchedule1 = $this->input->post('Scheduleby');
$preDeliverySchedule = $this->input->post('beforeSchedule');
$PlaceOforigin = $this->input->post('PlaceOforigin');
$preDate = $this->input->post('beforeDate');
$Date = $this->input->post('Deliverydate');
$Otherpayment=$this->input->post('Otherpayment');
$Otherpaymentamend=$this->input->post('Otherpayment');
$PreServiceTotalorder = $this->input->post('preServiceTotalorderValue');//For Domestic Pre Total Value
$Totalserviceorder = $this->input->post('Totalservicesummary');//For Domestic Revised Total value
$TotalCapitalorder= $this->input->post('CapitalToatlOrder');//For International total CapitalOrder
$preTotalCapitalorder= $this->input->post('preinterTotalorderValue');//For International pre total CapitalOrder
$ModeOfShipment=$this->input->post('addmodeofshipment'); $SupplierReference=$this->input->post('amendsupplierreference');
$SuppliersOfferNo=$this->input->post('amendsupplierofferno');
$OtherReferences=$this->input->post('amendotherreference');
$Fincap=$this->input->post('amendfincap');
$InsuranceOptions=$this->input->post('insuranceStatus');
$InsuranceNo=$this->input->post('insuranceNo');
$ServiceTypeOptions=$this->input->post('PoTypeOptions');
if($PoRange==1){
$MAD.="Current TotalOrder Value:&nbsp;&nbsp;" . $PreServiceTotalorder . "<br>";
}else if($PoRange==0){
$MAD.="Current TotalOrder Value:&nbsp;&nbsp;" . $preTotalCapitalorder . "<br>";
}
if($PaymentMethod != $prePaymentmethod)
{
if($prePaymentmethod != 'PT08'){ $Otherpaymentamend='';}
$MAD.="Current Paymemnt Terms :&nbsp;&nbsp;" .$prePaymentmethodtext."<br>";
}
if($predispatch != $curdispatch)
{
$MAD.="Current Delivery Option :&nbsp;&nbsp;" .$predispatch.$preDeliverySchedule.$preDate."<br>";
}
if($DeliverySchedule1!= $preDeliverySchedule)
{
$MAD.="Current DeliveyOption :&nbsp;&nbsp;" .$preDeliverySchedule.$preDate.$predispatch."<br>";
}
if($preDate != $Date)
{
$MAD.="Current DeliveyOption :&nbsp;&nbsp;" .$preDate.$preDeliverySchedule."<br>";
}
$capitalType = $this->input->post('capitalType');
$currencytypeID = $this->input->post('currencytype');
if($capitalType=='1'){
$CapitalRange = '1';
$ExchangeRateOn = '';
$ExchangeRate='';
}
else{
$CapitalRange = '0';
$ExchangeRateOn = $this->input->post('ExchangeRateOn');
$ExchangeRateOn = $this->getDateformat($ExchangeRateOn);
$ExchangeRate=$this->input->post('ExchangeRt');
}
$SpcialInstruction = $this->input->post('txtSpcialInstruction');
if($PoRange==1){
$FinalTotalOrder = $Totalserviceorder;
}else if($PoRange==0)
{
$FinalTotalOrder=$TotalCapitalorder;
}
$POStatus = $this->input->post('txtStatus');
$CreateBy = $this->session->userdata ( 'userId' );
$RowCount = $this->input->post('txtRowCount');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$createddt = $dt->format('Y-m-d H:i:s');
$updateddt = $dt->format('Y-m-d H:i:s');
$qtycheck = $this->purchaseorder_model->getqtycheck($PONO);
$qtycheckresult='';
foreach($qtycheck as $qty)
{
$qtycheckresult= $qty->IsQualityChkReqired;
}
if(empty($Deliverydt)){
$Deliverydt=null;
}
if($PaymentMethod != 'PT08'){
$Otherpayment='';
}
$updatedBy = $this->session->userdata ( 'userId' );
$POMaster = array('ParentPO'=>$PONO,'SupplierID'=>$SupplierID, 'TotalOrderValue'=>$FinalTotalOrder,'POType'=>$POType,'PODate'=>$PODate,'Status'=>PO_RELEASED,'CapitalRange'=>$PoRange,'ExchangeRate'=>$ExchangeRate,'ExchangeRateCalculatedon'=>$ExchangeRateOn,'PaymentTerms'=>$PaymentMethod,'PaymentOtherDescription'=>$Otherpayment,'ServiceDescription'=>$SpcialInstruction,'CreatedBy'=>$CreateBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'CreatedDate'=>$createddt,'ReleasedBy'=>$updatedBy,'ReleasedOn'=>$updateddt,'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'CurrencyType'=>$currencytypeID,'AmendedDetails'=>$MAD,'Import_DispatchDetails'=>$curdispatch,'Import_PlaceofOrgin'=>$PlaceOforigin,'Supplier_Reference'=>$SupplierReference,'Mode_Of_Shipment'=>$ModeOfShipment,'Supplier_Offer_No'=>$SuppliersOfferNo,'Other_Reference'=>$OtherReferences,'Fincap'=>$Fincap,'InsuranceStatus'=>$InsuranceOptions,'InsuranceNumber'=>$InsuranceNo,'POSubType'=>$ServiceTypeOptions,'IsQualityChkReqired'=>$qtycheckresult);
$LastPO = $this->purchaseorder_model->addAmendPOMaster($POMaster,$CreateBy,$PONO);
foreach($LastPO as $PO):
$NewPO=$PO['PONO'];
endforeach;
$PODetail=array('Status'=>PO_AMENDED);//TO SET PARENT PO AS AMENDMENT STATUS
$APO=$this->purchaseorder_model->updateAmendPOMaster($PONO,$PODetail);
$LineItemStatus = REQITEM_NEW;
$igrvalue = $this->purchaseorder_model->selectigrmaster($PONO);
$po = '';
$igrno ='';
foreach ($igrvalue as $value) {
$igrno = $value->IGRNO;
$po =$value->PONO;
if($PONO == $po)
{
$NewPOno = array('PONO' =>$NewPO);
$this->purchaseorder_model->updateigrmaster($igrno,$NewPOno);
}
}
for ($i = 1; $i <= $RowCount; $i++)
{
$CAD='';
$MaterialCode = $this->input->post('materialCode'.$i);
$Quantity = $this->input->post('quantity'.$i);
$preQuantity = $this->input->post('beforequantity'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$preitemRate = $this->input->post('itemRate'.$i);
$itemRate = $this->input->post('rateInUs'.$i);
$Per = $this->input->post('per'.$i);
$Exchangerate = $this->input->post('echangeRate'.$i);
$BasicPriceinmton = $this->input->post('rateInUs'.$i);
$Productprice = $this->input->post('basicvalInINR'.$i);
$LandingCharge = $this->input->post('beforeLanding'.$i);
$AfterLandingCharge = $this->input->post('landingCharge'.$i);
$CustomDuty = $this->input->post('beforeCustomDuty'.$i);
$AfterCustomDuty = $this->input->post('CustomDuty'.$i);
$CustomEd= $this->input->post('beforeCustomEDCess'.$i);
$AfterCustomEd= $this->input->post('CustomEDCess'.$i);
$CustomSH = $this->input->post('beforeCustomSHCess'.$i);
$AfterCustomSH = $this->input->post('CustomSHCess'.$i);
$Grossdutypayable = $this->input->post('GrossDutyPayable'.$i);
$purchaseratePerKG = $this->input->post('purchaseRate'.$i);
$CustomDutyExpensesPerKG = $this->input->post('CustomDutyExpenses'.$i);
$QuantityKG = $this->input->post('PurQuantity'.$i);
$Totalvalueitem=$this->input->post('PerKgExpense'.$i);
$Assable=$this->input->post('AssessableValue'.$i);
$beforeAssable=$this->input->post('beforeAssessableValue'.$i);
$Subtotal=$this->input->post('SubTotal'.$i);
$beforeSubtotal=$this->input->post('beforeSubTotal'.$i);
$Igst=$this->input->post('IGSTInt'.$i);
$beforeIgst=$this->input->post('beforeIGSTInt'.$i);
$AfterIgst=$this->input->post('AfterIGSTInt'.$i);
$ClearingCharge = $this->input->post('ClearingCharge'.$i);
$NetValue = $this->input->post('NetValue'.$i);
$DutyImpact=$this->input->post('DutyImpact'.$i);
$CostCenter = $this->input->post('CPCostCode'.$i);
$SGST = $this->input->post('SGST'.$i);
$preSGST = $this->input->post('beforeSGST'.$i);
$CGST = $this->input->post('CGST'.$i);
$preCGST = $this->input->post('beforeCGST'.$i);
$IGST = $this->input->post('IGST'.$i);
$preIGST = $this->input->post('beforeIGST'.$i);
$SGSTvalue=$this->input->post('afterSGST'.$i);
$preSGSTvalue=$this->input->post('beforeSGSTvalue'.$i);
$CGSTvalue=$this->input->post('afterCGST'.$i);
$preCGSTvalue=$this->input->post('beforeCGSTvalue'.$i);
$IGSTvalue=$this->input->post('afterIGST'.$i);
$preIGSTvalue=$this->input->post('beforeIGSTvalue'.$i);
$otherallowance=$this->input->post('otherallowance'.$i);
$preotherallowance=$this->input->post('beforeotherallowance'.$i);
$DiscountType = $this->input->post('DisType'.$i);
$DiscountValue = $this->input->post('DisVal'.$i);
$AfterDiscount = $this->input->post('AfterDisVal'.$i);
$preDiscountType = $this->input->post('beforeDisType'.$i);
$preDiscountValue = $this->input->post('beforeDisVal'.$i);
$preAfterDiscount = $this->input->post('beforeAfterDisVal'.$i);
$TotalServiceOrderValue = $this->input->post('totalservicevalue'.$i);
$CapitalItemDescrition = $this->input->post('CapitalItemDescrition'.$i);
$FreightType = $this->input->post('FreightType'.$i);
$FreightValue = $this->input->post('FreightVal'.$i);
$AfterFreightValue = $this->input->post('AfterFreightVal'.$i);
$NOOfTrip = $this->input->post('NoOfTrip'.$i);
$POLineItemNo = $this->input->post('LineItemNo'.$i);
$FreightTypeloc=$this->input->post('Ftype'.$i);
$FreightNoofTriploc=$this->input->post('NoTrip'.$i);
$Freightrateloc=$this->input->post('Fvalue'.$i);
$FreightAmountloc=$this->input->post('Afvalue'.$i);
$beforeFreightTypeloc=$this->input->post('beforeFtype'.$i);
$beforeFreightNoofTriploc=$this->input->post('beforeNoTrip'.$i);
$beforeFreightrateloc=$this->input->post('beforeFvalue'.$i);
$beforeFreightAmountloc=$this->input->post('beforeAfvalue'.$i);
$rowspanvalue=0;
if($Quantity != $preQuantity)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Qty :&nbsp;" . $preQuantity ."</td><td>Revised Qty :&nbsp;" . $Quantity . "</td></tr>";
}
if($itemRate != $preitemRate)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Rate :&nbsp;" . $preitemRate ."</td><td>Revised Rate :&nbsp;" . $itemRate . "</td></tr>";
}
if($PoRange==1){
if(($DiscountValue!=$preDiscountValue) && ($AfterDiscount!=$preAfterDiscount)){
$rowspanvalue+=2;
$CAD.="<tr><td>Current Discount :&nbsp;" . $preDiscountValue ."</td><td>Revised Discount :&nbsp;" . $DiscountValue . "</td></tr><tr><td>Current Discount value :&nbsp;" . $preAfterDiscount ."</td><td>Revised Discount value:&nbsp;" . $AfterDiscount . "</td></tr>";
}
if(($SGST != $preSGST) && ($SGSTvalue != $preSGSTvalue))
{
$rowspanvalue+=2;
$CAD.="<tr><td>Current SGST% :&nbsp;" . $preSGST ."</td><td>Revised SGST% :&nbsp;" . $SGST . "</td></tr><tr><td>Current SGST value :&nbsp;" . $preSGSTvalue ."</td><td>Revised SGST value:&nbsp;" . $SGSTvalue . "</td></tr>";
}
if(($CGST != $preCGST) && ($CGSTvalue != $preCGSTvalue))
{
$rowspanvalue+=2;
$CAD.="<tr><td>Current CGST% :&nbsp;" . $preCGST ."</td><td>Revised CGST% :&nbsp;" . $CGST . "</td></tr><tr><td>Current CGST value :&nbsp;" . $preCGSTvalue ."</td><td>Revised CGST value:&nbsp;" . $CGSTvalue . "</td></tr>";
}
if(($IGST != $preIGST) && ($IGSTvalue != $preIGSTvalue))
{
$rowspanvalue+=2;
$CAD.="<tr><td>Current IGST% :&nbsp;" . $preIGST ."</td><td>Revised IGST% :&nbsp;" . $IGST . "</td></tr><tr><td>Current IGST value :&nbsp;" . $preIGSTvalue ."</td><td>Revised IGST value:&nbsp;" . $IGSTvalue . "</td></tr>";
}
if($otherallowance != $preotherallowance)
{
$rowspanvalue++;
$CAD.="<tr><td>Current OtherAllowances :&nbsp;" . $preotherallowance ."</td><td>Revised OtherAllowances :&nbsp;" . $otherallowance . "</td></tr>";
}
if($FreightTypeloc != $beforeFreightTypeloc)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Freight Type :&nbsp;" . $beforeFreightTypeloc ."</td><td>Revised Qty :&nbsp;" . $FreightTypeloc . "</td></tr>";
}
if($FreightNoofTriploc != $beforeFreightNoofTriploc)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Freight Nooftrips :&nbsp;" . $beforeFreightNoofTriploc ."</td><td>Revised Freight Nooftrips:&nbsp;" . $FreightNoofTriploc . "</td></tr>";
}
if($Freightrateloc != $beforeFreightrateloc)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Freight Rate :&nbsp;" . $beforeFreightrateloc ."</td><td>Revised Freight Rate:&nbsp;" . $Freightrateloc . "</td></tr>";
}
if($FreightAmountloc != $beforeFreightAmountloc)
{
$rowspanvalue++;
$CAD.="<tr><td>Current Freight Amount :&nbsp;" .$beforeFreightAmountloc ."</td><td>Revised Freight Amount:&nbsp;" . $FreightAmountloc . "</td></tr>";
}
if(($Assable-$beforeAssable)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Assessable : ".$beforeAssable ."</td><td>Revised CustomDuty:".$Assable."</td></tr>";
}
if(($Subtotal-$beforeSubtotal)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Subtotal : ".$beforeSubtotal ."</td><td>Revised Subtotal:".$Subtotal."</td></tr>";
}
if(($Igst-$beforeIgst)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current IGST Percentage : ".$beforeIgst ."</td><td>Revised IGST Percentage:".$Igst."</td></tr>";
}
}
if($rowspanvalue>0)
{
$rowspanvalue++;
$CAD2='';
$CAD2=$CAD;
$CAD='';
$CAD="<tr><td rowspan=". $rowspanvalue .">".$MaterialCode."</td></tr>";
$CAD.=$CAD2;
}
$POLineItemList = array('PONO'=>$NewPO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'CostCenterCode'=>$CostCenter,'AmendedDetails'=>$CAD,'Per'=>$Per,'ServiceMaterialDescription'=>$CapitalItemDescrition);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
$LineItemNo = '';
foreach($POLineItem as $line):
$LineItemNo = $line['LineItemNo'];
endforeach;
if(trim($POType) == CAPITAL )
{
if($capitalType=='1'){
$ServiceTaxList = array('LineItemNo'=>$LineItemNo, 'CGST'=>$CGST,'After_CGST'=>$CGSTvalue,'SGST'=>$SGST,'After_SGST'=>$SGSTvalue,'IGST'=>$IGST,'After_IGST'=>$IGSTvalue, 'otherallowance'=>$otherallowance,'TotalValue'=>$TotalServiceOrderValue,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'discount'=>$DiscountType,'discountval'=>$DiscountValue,'Afterdiscountval'=>$AfterDiscount,'FreightType'=>$FreightTypeloc,'NoOfTrip'=>$FreightNoofTriploc,'FreightValue'=>$Freightrateloc,'AfterFreightValue'=>$FreightAmountloc);
$ServiceTax = $this->purchaseorder_model->addServiceTax($ServiceTaxList);
}
else if($capitalType=='0'){
$ImportTaxList = array('LineItemNo'=>$LineItemNo, 'BasicPriceInMTon'=>$BasicPriceinmton,'ProductPrice'=>$Productprice,'LandingCharge'=>$LandingCharge,'AfterLandingCharge'=>$AfterLandingCharge,'CustomDuty'=>$CustomDuty,'AfterCustomDuty'=>$AfterCustomDuty,'CustomEdCess'=>$CustomEd,'CustomSHCess'=>$CustomSH,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'Grossdutypayable'=>$Grossdutypayable,'CustomDutyExpensesPerKG'=>$CustomDutyExpensesPerKG,'QuantityKG'=>$QuantityKG,'AfterCustomSHCess'=>$AfterCustomSH,'AfterCustomEdCess'=>$AfterCustomEd,'TotalValue'=>$Totalvalueitem,'FreightType'=>$FreightType,'NoOfTrip'=>$NOOfTrip,'FreightValue'=>$FreightValue,'AfterFreightValue'=>$AfterFreightValue,'AssessableValue'=>$Assable,'SubTotal'=>$Subtotal,'IGST'=>$Igst,'AfterIGST'=>$AfterIgst,'DutyImpact'=>$DutyImpact,'NetValue'=>$NetValue,'ClearingCharge'=>$ClearingCharge);
$ImportList = $this->purchaseorder_model->addImportTax($ImportTaxList);
}
}
}
$ordqty ='';
$recqty ='';
$qty = $this->purchaseorder_model->getpolineqty($NewPO);
$ordqty = $qty[0]->Qty;
$recqty = $qty[0]->rec;
if($ordqty == $recqty)
{
$Newstatus = array('Status'=>IGR_CREATED);
$this->purchaseorder_model-> POLineItemsupdatestatus($NewPO,$Newstatus);
$Newstat = array('Status'=>IGR_CREATED);
$this->purchaseorder_model->pomasterupdatestatus($NewPO,$Newstat);
}
echo 'Purchase Order'.$PONO.'Amended Successfully! New PO Number Is: '.$NewPO ;
}
/**
* To Store release import Po values after edit
*/
function EditAmendImportPO()
{
$MAD='';
$PONO =$this->input->post('txtPONO');
$POdt = '';
$createddt='';
$PODate = $this->getDateformat($POdt);
$SupplierID = $this->input->post('drpSupplier');
$DeliveryAddr = $this->input->post('DeliveryAddr');
$dt = $this->input->post('Deliverydt');
$Deliverydt = $this->getDateformat($dt);
$POType = $this->input->post('POType');
$PoRange = $this->input->post('txtPoRange');
$updatedBy = $this->session->userdata ( 'userId' );
$Exchangerate=$this->input->post('ExchangeRate');
$Edt=$this->input->post('Exchangerateon');
$ExchangeRateCalculatedon=$this->getDateformat($Edt);
$CurrencyType=$this->input->post('currencytype');
$DeliveryOption = $this->input->post('DateRange');
$DeliverySchedule='';
$Dispatch='';
if($DeliveryOption==1)
{
$Dispatch='';
$DeliverySchedule = $this->input->post('Scheduleby');
}
else
{
$Dispatch = $this->input->post('Dispatch');
$DeliverySchedule = '';
}
$SpcialInstruction = $this->input->post('txtSpcialInstruction');
$TotalOrder = $this->input->post('txttot');
$AmendTotal=$this->input->post('txttotamend');
$MAD.="Current Total Order Value:&nbsp;&nbsp;:" . $AmendTotal ."<br>";
$POStatus = $this->input->post('txtStatus');
$CreateBy = $this->session->userdata ( 'userId' );
$RowCount = $this->input->post('txtRowCount');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$createddt = $dt->format('Y-m-d H:i:s');
$updateddt = $dt->format('Y-m-d H:i:s');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updateddt = $dt->format('Y-m-d H:i:s');
$PaymentTerms=$this->input->post('PaymentTerms');
$beforePaymentTerms=$this->input->post('beforePaymentterms');
$Shipmentmode=$this->input->post('addmodeofshipment');
$SupplierRef=$this->input->post('amendsupplierreference');
$SupplierOffer=$this->input->post('amendsupplierofferno');
$otherRef=$this->input->post('amendotherreference');
$finCap=$this->input->post('amendfincap');
$OtherPayment=$this->input->post('Otherpayment');
$Insurance=$this->input->post('Insurance');
$qtycheck = $this->purchaseorder_model->getqtycheck($PONO);
$qtycheckresult='';
foreach($qtycheck as $qty)
{
$qtycheckresult= $qty->IsQualityChkReqired;
}
if($Insurance=='YES')
{
$Insurancenumber=$this->input->post('insurancenumber');
$insurestatus='1';
}
else
{
$Insurancenumber='';
$insurestatus='0';
}
$importoption=$this->input->post('Importoption');
if($PaymentTerms!=$beforePaymentTerms)
{
$MAD.="Current Payment Terms&nbsp;&nbsp;" . $beforePaymentTerms."<br>";
}
$Palaceoforigin=$this->input->post('PlaceOforigin');
$beforePalaceoforigin=$this->input->post('beforePlaceOforigin');
if($Palaceoforigin!=$beforePalaceoforigin)
{
$MAD.=$MAD."Current Place of Origin:&nbsp;&nbsp;" . $beforePalaceoforigin."<br>";
}
$POMaster = array('ParentPO'=>$PONO,'SupplierID'=>$SupplierID, 'POType'=>$POType,'TotalOrderValue'=>$TotalOrder,'PODate'=>$PODate,'Status'=>$POStatus,'PORange'=>$PoRange,'ServiceDescription'=>$SpcialInstruction,'CreatedBy'=>$CreateBy,'DeliveryAddress'=>$DeliveryAddr,'Import_DispatchDetails'=>$Dispatch,'CreatedDate'=>$createddt,'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'ExchangeRate'=>$Exchangerate,'ExchangeRateCalculatedon'=>$ExchangeRateCalculatedon,'CurrencyType'=>$CurrencyType,'PaymentTerms'=>$PaymentTerms,'ReleasedBy'=>$updatedBy,'ReleasedOn'=>$updateddt,'Import_PlaceofOrgin'=>$Palaceoforigin,'Mode_Of_Shipment'=>$Shipmentmode,'Supplier_Reference'=>$SupplierRef,'Supplier_Offer_No'=>$SupplierOffer,'Other_Reference'=>$otherRef,'Fincap'=>$finCap,'AmendedDetails'=>$MAD,'PaymentOtherDescription'=>$OtherPayment,'InsuranceStatus'=>$insurestatus,'InsuranceNumber'=>$Insurancenumber,'POSubType'=>$importoption,'IsQualityChkReqired'=>$qtycheckresult);
$LastPO = $this->purchaseorder_model->addAmendPOMaster($POMaster,$CreateBy,$PONO);
$NewPO = '';
if(count($LastPO)>0)
{
$NewPO = $LastPO[0]['PONO'];
}
$PODetail=array('Status'=>PO_AMENDED);//TO SET PARENT PO AS AMENDMENT STATUS
$APO=$this->purchaseorder_model->updateAmendPOMaster($PONO,$PODetail);
$LineItemStatus = REQITEM_NEW;
$igrvalue = $this->purchaseorder_model->selectigrmaster($PONO);
$po = '';
$igrno ='';
foreach ($igrvalue as $value) {
$igrno = $value->IGRNO;
$po =$value->PONO;
if($PONO == $po)
{
$NewPOno = array('PONO' =>$NewPO);
$this->purchaseorder_model->updateigrmaster($igrno,$NewPOno);
}
}
for ($i = 1; $i <= $RowCount; $i++)
{
$CAD='';
$MaterialCode = $this->input->post('materialCode'.$i);
$Quantity = $this->input->post('quantity'.$i);
$beforeQuantity=$this->input->post('beforequantity'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$itemRate = $this->input->post('itemRate'.$i);
$beforeitemRate=$this->input->post('beforeitemRate'.$i);
$BasicPriceinmton = $this->input->post('BasicPriceInMTon'.$i);
$Productprice = $this->input->post('ProductPrice'.$i);
$LandingCharge = $this->input->post('LandingCharge'.$i);
$beforeLandingCharge = $this->input->post('beforeLandingCharge'.$i);
$AfterLandingCharge = $this->input->post('AfterLandingCharge'.$i);
$CustomDuty = $this->input->post('CustomDuty'.$i);
$beforeCustomDuty=$this->input->post('beforeCustomDuty'.$i);
$AfterCustomDuty = $this->input->post('AfterCustomDuty'.$i);
$CustomEd= $this->input->post('CustomEdCess1'.$i);
$beforeCustomEd=$this->input->post('beforeCustomEdCess'.$i);
$AfterCustomEd= $this->input->post('AfterCustomEdCess1'.$i);
$CustomSH = $this->input->post('CustomSHCess'.$i);
$beforeCustomSH=$this->input->post('beforeCustomSHCess'.$i);
$AfterCustomSH = $this->input->post('AfterCustomSHCess'.$i);
$Grossdutypayable = $this->input->post('Grossdutypayable1'.$i);
$beforeGrossdutypayable = $this->input->post('beforeGrossdutypayable'.$i);
$Assable=$this->input->post('AssessableValue'.$i);
$beforeAssable=$this->input->post('beforeAssessableValue'.$i);
$Subtotal=$this->input->post('SubTotal'.$i);
$beforeSubtotal=$this->input->post('beforeSubTotal'.$i);
$Igst=$this->input->post('IGST'.$i);
$beforeIgst=$this->input->post('beforeIGST'.$i);
$AfterIgst=$this->input->post('AfterIGST'.$i);
$CustomDutyExpensesPerKG = $this->input->post('CustomDutyExpensesPerKG'.$i);
$beforeCustomDutyExpensesPerKG = $this->input->post('beforeCustomDutyExpensesPerKG'.$i);
$FreightType=$this->input->post('FreightType'.$i);
$NoOfTrip=$this->input->post('NoOfTrip'.$i);
$Freightrate=$this->input->post('FreightValue'.$i);
$Freightamount=$this->input->post('AfterFreightValue'.$i);
$per=$this->input->post('Per'.$i);
$beforeFreightType=$this->input->post('beforeFreightType'.$i);
$beforeNoOfTrip=$this->input->post('beforeNoOfTrip'.$i);
$beforeFreightrate=$this->input->post('beforeFreightValue'.$i);
$beforeFreightamount=$this->input->post('beforeAfterFreightValue'.$i);
$beforeper=$this->input->post('beforePer'.$i);
$QuantityKG = $this->input->post('QuantityKG'.$i);
$ClearingCharge = $this->input->post('ClearingCharge'.$i);
$NetValue = $this->input->post('NetValue'.$i);
$DutyImpact=$this->input->post('DutyImpact'.$i);
$specialinstruction=$this->input->post('Addinstruction'.$i);
$CostCenter = $this->input->post('costCode'.$i);
$Totalvalueitem=$this->input->post('txtTotalorderValue');
$RecQtyvalue=0;
$rowspanvalue=0;
$LineItemNo = '';
if(($itemRate-$beforeitemRate)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Rate : ".$beforeitemRate ."</td><td>Revised Rate:".$itemRate."</td></tr>";
}
if(($Quantity-$beforeQuantity)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Quantity : ".$beforeQuantity ."</td><td>Revised Quantity:".$Quantity."</td></tr>";
}
if(($LandingCharge-$beforeLandingCharge)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Landing percentage : ".$beforeLandingCharge ."</td><td>Revised Landing Percentage:".$LandingCharge."</td></tr>";
}
if(($CustomDuty-$beforeCustomDuty)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current CustomDuty : ".$beforeCustomDuty ."</td><td>Revised CustomDuty:".$CustomDuty."</td></tr>";
}
if($CustomEd-$beforeCustomEd)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current CustomEd : ".$beforeCustomEd ."</td><td>Revised CustomEd:".$CustomEd."</td></tr>";
}
if($CustomSH-$beforeCustomSH)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current CustomSH : ".$beforeCustomSH ."</td><td>Revised CustomSH:".$CustomSH."</td></tr>";
}
if($FreightType!=$beforeFreightType)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Freight Type: ".$beforeFreightType ."</td><td>Revised Freight Type:".$FreightType."</td></tr>";
}
if($NoOfTrip-$beforeNoOfTrip)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current No of Trip: ".$beforeNoOfTrip ."</td><td>Revised Additional Excise duty:".$NoOfTrip."</td></tr>";
}
if($Freightrate-$beforeFreightrate)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Freightrate: ".$beforeFreightrate ."</td><td>Revised Freightrate:".$Freightrate."</td></tr>";
}
if($Freightamount-$beforeFreightamount)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Freight Amount: ".$beforeFreightamount ."</td><td>Revised Freight Amount:".$Freightamount."</td></tr>";
}
if($per!=$beforeper)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Per Value: ".$beforeper ."</td><td>Revised Per Value:".$per."</td></tr>";
}
if(($Assable-$beforeAssable)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Assessable : ".$beforeAssable ."</td><td>Revised CustomDuty:".$Assable."</td></tr>";
}
if(($Subtotal-$beforeSubtotal)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Subtotal : ".$beforeSubtotal ."</td><td>Revised Subtotal:".$Subtotal."</td></tr>";
}
if(($Igst-$beforeIgst)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current IGST Percentage : ".$beforeIgst ."</td><td>Revised IGST Percentage:".$Igst."</td></tr>";
}
if(($Grossdutypayable-$beforeGrossdutypayable)!=0)
{
$rowspanvalue++;
$CAD=$CAD."<tr><td>Current Gross Duty Payable : ".$beforeGrossdutypayable ."</td><td>Revised Gross Duty Payable:".$Grossdutypayable."</td></tr>";
}
if($rowspanvalue>0)
{
$rowspanvalue++;
$CAD2='';
$CAD2=$CAD;
$CAD='';
$CAD="<tr><td rowspan=". $rowspanvalue .">".$MaterialCode."</td></tr>";
$CAD.=$CAD2;
}
$POLineItemList = array('PONO'=>$NewPO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'CostCenterCode'=>$CostCenter,'AmendedDetails'=>$CAD,'Per'=>$per,'ServiceMaterialDescription'=>$specialinstruction);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
if(count($POLineItem)>0)
{
$LineItemNo = $POLineItem[0]['LineItemNo'];
}
$ImportTaxList = array('LineItemNo'=>$LineItemNo,'BasicPriceInMTon'=>$BasicPriceinmton,'ProductPrice'=>$Productprice,'LandingCharge'=>$LandingCharge,'AfterLandingCharge'=>$AfterLandingCharge,'CustomDuty'=>$CustomDuty,'AfterCustomDuty'=>$AfterCustomDuty,'CustomEdCess'=>$CustomEd,'CustomSHCess'=>$CustomSH,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'Grossdutypayable'=>$Grossdutypayable,'CustomDutyExpensesPerKG'=>$CustomDutyExpensesPerKG,'QuantityKG'=>$QuantityKG,'AfterCustomSHCess'=>$AfterCustomSH,'AfterCustomEdCess'=>$AfterCustomEd,'TotalValue'=>$Totalvalueitem,'FreightType'=>$FreightType,'NoOfTrip'=>$NoOfTrip,'FreightValue'=>$Freightrate,'AfterFreightValue'=>$Freightamount,'AssessableValue'=>$Assable,'SubTotal'=>$Subtotal,'IGST'=>$Igst,'AfterIGST'=>$AfterIgst,'DutyImpact'=>$DutyImpact,'NetValue'=>$NetValue,'ClearingCharge'=>$ClearingCharge);
$ImportList = $this->purchaseorder_model->addImportTax($ImportTaxList);
}
$ordqty ='';
$recqty ='';
$qty = $this->purchaseorder_model->getpolineqty($NewPO);
$ordqty = $qty[0]->Qty;
$recqty = $qty[0]->rec;
if($ordqty == $recqty)
{
$Newstatus = array('Status'=>IGR_CREATED);
$this->purchaseorder_model-> POLineItemsupdatestatus($NewPO,$Newstatus);
$Newstat = array('Status'=>IGR_CREATED);
$this->purchaseorder_model->pomasterupdatestatus($NewPO,$Newstat);
}
echo 'Purchase Order is'.$PONO.'Amended Successfully! New PO Number is: '.$NewPO ;
}
/**
* To convert the dateformat (date with time) and store to DB
*/
function getDateformat($Val)
{
$date = new DateTime($Val,new DateTimeZone('Asia/Kolkata'));
$retDate = $date->format('Y-m-d H:i:s');
return $retDate;
}
}