siddharth_application/application/controllers/amendmentpurchaseorder.php
venbatechnologies@gmail.com 3650012dcb capital po updates done
2017-06-30 20:49:26 +05:30

397 lines
16 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : Amendment Purchase Order controller
* User Class to control all user related operations.
* @author : Saravana kumar
* @version : 1.1
* @since : 19 June 2016
*/
class amendmentpurchaseorder extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
//$this->load->model('amendment_model');
$this->load->model('purchaseorder_model');
$this->load->library('session');
$this->load->library('form_validation');
// $this->load->library('pagination');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the user
*/
public function index()
{
$this->load->library('pagination');
// $count = $this->purchaseorder_model->purchaseorderListingCount('');
//$returns = $this->paginationCompress ( "purchaseorderListing/", $count, 10 );
//$this->purchaseorder_model->UpdateRequistionStatus(); CONFORM IT
$forwhat='amendment';
$data['POData'] = $this->purchaseorder_model->purchaseorderListing($forwhat);
$this->global['pageTitle'] = 'Siddharth : Amendment Purchase Order';
$this->loadviews('AmendPOlist',$this->global,$data,NULL);
}
function EditAmendPurchaseOrder()
{
$PONO = $_GET['PONO'];
$ReqType = $_GET['ReqType'];
$Req = $this->purchaseorder_model->getRequistionNoFromPO($PONO);
$data['ReqList'] = $Req ;
$result = array();
$ReqArray = array();
foreach ($Req as $SID):
$ReqArray[] = $SID->ReqNo ;
$result[] = $this->purchaseorder_model->getRawPOMaterialList($SID->ReqNo);
endforeach;
$data['MaterialList'] = $result;//$this->purchaseorder_model->getRawMaterialList($ReqType,$ReqArray);
$data['Suplist'] = $this->purchaseorder_model->getSupplierName();
/* Cost code from Requisition - Client Review Fix
Start here */
$ReqDetails = $this->purchaseorder_model->getRequistDetails($ReqArray);
$data['RequistionDetails'] = $ReqDetails;
$CostCode = '';
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$Year = $dt->format('Y');
foreach ($ReqDetails as $Rs):
$CostCode = $Rs->CostCenterCode;
endforeach;
$AvlBudget = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode,$Year,$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');
if($ReqType == SERVICE)
{
$data['POItem'] = $this->purchaseorder_model->GetServicePurchaseOrderDetails($PONO);
$this->global['pageTitle'] = 'Siddharth : Edit Service Purchase order form';
$this->loadViews("editServiceAmendPO", $this->global, $data, NULL);
}
else if($ReqType == REVENUE)
{
$data['POItem'] = $this->purchaseorder_model->GetRevenuePurchaseOrderDetails($PONO);
$this->global['pageTitle'] = 'Siddharth : Edit Revenue Purchase order form';
$this->loadViews("editRevenueAmendPO", $this->global, $data, NULL);
}
else if($ReqType == IMPORT)
{
$AvlBudget = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode,$Year,$ReqType);
if(count($AvlBudget)>0)
{
$data['AvlBudAmt'] = $AvlBudget[0]['BudgetAmount'] - $AvlBudget[0]['Totalvalue'];
}
// print_r($data);
$data['POItem'] = $this->purchaseorder_model->GetImportPurchaseOrderDetails($PONO);
//print_r($data);
//$data['ExchangeRate']=$data['POItem']->ExchangeRate;
//print_r($data['POItem']);
foreach($data['POItem'] as $Rate)
{
// print_r($Rate->ExchangeRate);
$exRate=$Rate->ExchangeRate;
// $data[$Rate->ExchangeRate]=$Rate->ExchangeRate;
}
foreach($data['POItem'] as $CUR)
{
//print_r($CUR->CurrencyType);
$Currency=$CUR->CurrencyType;
// $data[$Rate->ExchangeRate]=$Rate->ExchangeRate;
}
//echo "$Currency";
$data['CurrencyDetail']=$this->purchaseorder_model->GetCurrencyDetail($Currency);
//print_r($data);
$data['ExchangeRate']=$exRate;
$data['Currency']=$this->purchaseorder_model->GetCurrencytype();
//print_r($data);
$this->global['pageTitle'] = 'Siddharth : Edit Import Purchase order form';
$this->loadViews("editImportAmendPO", $this->global, $data, NULL);
}
}
function EditRevenuePurchaseOrder()
{
$NewPO='0';
$PONO =$this->input->post('txtPONO');
echo "OLD PO IS" . $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');
//$Deliverydt = $this->getDateformat($dt);
$DeliveryOption = $this->input->post('DateRange');
if($DeliveryOption==1){
$Deliverydt = '';
$DeliverySchedule = $this->input->post('Scheduleby');
}
else{
$Deliverydt = $this->getDateformat($dt);
$DeliverySchedule = '';
}
$POType = $this->input->post('POType');
$PoRange = $this->input->post('txtPoRange');
$SpcialInstruction = $this->input->post('SpcialInstruction');
$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');
// PO Master
// PO Master
$POMaster = array('ParentPO'=>$PONO,'SupplierID'=>$SupplierID, 'TotalOrderValue'=>$TotalOrderValueSummary,'PODate'=>$PODate,'Status'=>'ST015','DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'ServiceDescription'=>$SpcialInstruction,'CreatedBy'=>$updatedBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'UpdatedOn'=>$updateddt );
//$POMaster = $this->purchaseorder_model->updatePOMaster($PONO,$POList);
$LastPO = $this->purchaseorder_model->addPOMaster($POMaster);
foreach($LastPO as $PO):
$NewPO=$PO->PONO;
endforeach;
echo "NEW PO IS " . $NewPO;
echo "";
//change old po status as Amendment
$PODetail=array('Status'=>"ST030");//TO SET PARENT PO AS AMENDMENT STATUS
print_r($PODetail);
$APO=$this->purchaseorder_model->updateAmendPOMaster($PONO,$PODetail);
echo $APO."Affected";
//die();
//print_r($LastPO);
$LineItemStatus = REQITEM_NEW;
echo 'before for loop';
echo $RowCount;
for ($i = 1; $i <= $RowCount; $i++)
{
echo "inside loop";
$MaterialCode = $this->input->post('materialCode'.$i);
$Quantity = $this->input->post('quantity'.$i);
$Reqnumber = $this->input->post('Reqnumber'.$i);
$itemRate = $this->input->post('itemRate'.$i);
$DiscountType = $this->input->post('DisType'.$i);
$DiscountValue = $this->input->post('DisVal'.$i);
$AfterDiscount = $this->input->post('AfterDisVal'.$i);
$PackagingOption = $this->input->post('PackOption'.$i);
$PackagingType = $this->input->post('PackType'.$i);
$PackagingValue = $this->input->post('PackVal'.$i);
$AfterPackagingValue = $this->input->post('AfterPackVal'.$i);
$ExciseOption = $this->input->post('ExciseOption'.$i);
$ExciseValue = $this->input->post('ExciseVal'.$i);
$AfterExciseValue = $this->input->post('AfterExciseVal'.$i);
$VatOption = $this->input->post('VatOption'.$i);
$VatValue = $this->input->post('VatVal'.$i);
$AfterVatValue = $this->input->post('AfterVatVal'.$i);
$CSTOption = $this->input->post('CSTOption'.$i);
$CSTValue = $this->input->post('CSTVal'.$i);
$AfterCSTValue = $this->input->post('AfterCSTVal'.$i);
$GSTValue = $this->input->post('GSTVal'.$i);
$AfterGSTValue = $this->input->post('AfterGSTVal'.$i);
$OtherTaxValue = $this->input->post('OtherTaxVal'.$i);
$AfterOtherTaxValue = $this->input->post('AfterOtherTaxVal'.$i);
$FreightType = $this->input->post('FreightType'.$i);
$FreightValue = $this->input->post('FreightVal'.$i);
$AfterFreightValue = $this->input->post('AfterFreightVal'.$i);
$InsuranceValue = $this->input->post('Insval'.$i);
$TotalOrderValue = $this->input->post('TotalOrderValue'.$i);
$POLineItemNo = $this->input->post('LineItemNo'.$i);
$CostCenter = $this->input->post('costCode'.$i);
$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)
// {
$POLineItemList = array('PONO'=>$NewPO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt,'CostCenterCode'=>$CostCenter);
print_r($POLineItemList);
$POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList);
// if(count($POLineItem)>0)
// {
foreach($POLineItem as $line):
$LineItemNo = $line->LineItemNo;
endforeach;
echo "Lineitem no is" . $LineItemNo;
//print_r($LineItemNo);
// }
//}
// else
// {
// $LineItemNo = $POLineItemNo;
// $POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'UpdateBY'=>$updatedBy,'UpdatedOn'=>$updateddt,'CostCenterCode'=>$CostCenter);
// $POLineItem = $this->purchaseorder_model->updatePOLineItem($PONO,$POLineItemNo,$POLineItemList);
// }
// $isExists = $this->purchaseorder_model->LineItemExistsinRevenueTax($LineItemNo);
// if(count($isExists) == 0)
// {
$RevenueTaxList = array('LineItemNo'=>$LineItemNo, 'DiscountType'=>$DiscountType,'DiscountValue'=>$DiscountValue,'AfterDiscount'=>$AfterDiscount,'PackagingType'=>$PackagingType,'PackagingValue'=>$PackagingValue,'PackagingCalulatedOn'=>$PackagingOption,'AfterPackagingValue'=>$AfterPackagingValue,'FreightType'=>$FreightType, 'FreightValue'=>$FreightValue,'AfterFreightValue'=>$AfterFreightValue,'ExciseDuty'=>$ExciseValue,'ExciseDutyCalulatedOn'=>$ExciseOption,'AfterExciseDuty'=>$AfterExciseValue,'Vat'=>$VatValue,'AfterVAT'=>$AfterVatValue,'VatCalulatedOn'=>$VatOption, 'CST'=>$CSTValue,'AfterCST'=>$AfterCSTValue,'CSTCalulatedOn'=>$CSTOption,'GST'=>$GSTValue,'AfterGST'=>$AfterGSTValue,'OtherTaxes'=>$OtherTaxValue,'AfterOtherTaxes'=>$AfterOtherTaxValue,'Insurance'=>$InsuranceValue,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt);
$RevenueList = $this->purchaseorder_model->addRevenueTax($RevenueTaxList);
// }
// else
// {
// $RevenueTaxList = array('DiscountType'=>$DiscountType,'DiscountValue'=>$DiscountValue,'AfterDiscount'=>$AfterDiscount,'PackagingType'=>$PackagingType,'PackagingValue'=>$PackagingValue,'PackagingCalulatedOn'=>$PackagingOption,'AfterPackagingValue'=>$AfterPackagingValue,'FreightType'=>$FreightType, 'FreightValue'=>$FreightValue,'AfterFreightValue'=>$AfterFreightValue,'ExciseDuty'=>$ExciseValue,'ExciseDutyCalulatedOn'=>$ExciseOption,'AfterExciseDuty'=>$AfterExciseValue,'Vat'=>$VatValue,'AfterVAT'=>$AfterVatValue,'VatCalulatedOn'=>$VatOption, 'CST'=>$CSTValue,'AfterCST'=>$AfterCSTValue,'CSTCalulatedOn'=>$CSTOption,'GST'=>$GSTValue,'AfterGST'=>$AfterGSTValue,'OtherTaxes'=>$OtherTaxValue,'AfterOtherTaxes'=>$AfterOtherTaxValue,'Insurance'=>$InsuranceValue,'TotalValue'=>$TotalOrderValue, 'UpdateBY'=>$updatedBy,'UpdatedOn'=>$updateddt);
// $this->purchaseorder_model->updateRevenueTax($LineItemNo,$RevenueTaxList);
// }
}
echo 'Purchase Order Amended Successfully! PO Number Is: '.$PONO .'- New PO Number is'.$NewPO;
}
function getDateformat($Val)
{
$date = new DateTime($Val,new DateTimeZone('Asia/Kolkata'));
$retDate = $date->format('Y-m-d H:i:s');
return $retDate;
}
/* ---------------------------------OLD AMENDPO FUNCTION-----------------------------------------------*/
function getpodetails()
{
$PONO=$this->input->post('pono');
//$PONO='PO0001';
$result = $this->amendment_model->getPODetails($PONO);
// print_r($result);
$obj=json_encode($result);
echo $obj;
//print_r($obj);
//die();
}
function updatepo(){
$someArray = $_GET['jsondata'];
//$PONO = $_GET['pono'];
$PONO = $this->input->get('PONO');
$rowsaffected=0;
$porow=0;
//echo $PONO."</br>";
// print_r($someArray);
$d=json_decode($someArray);
////print_r( $d);
foreach($d as $d1){
$MaterialCode=$d1->ItemCode;
$Quantity=$d1->Ordered_Quantity;
$ReceivedQuantity=$d1->Additional_Quantity_Received;
$Remarks=$d1->Remarks;
$Status='ST031';
$POstatus='ST030';
$store=array('Quantity'=>$Quantity,'AmendmentQuantity'=>$ReceivedQuantity,'AmendmentRemarks'=>$Remarks,'Status'=>$Status);
//print_r($store);
$result=$this->amendment_model->updatePODetails($PONO,$MaterialCode,$store,$POstatus);
$rowsaffected++;
}
echo "<script>alert($rowsaffected+'--Rows Affected')</script>";
$data['PODetails']=$this->amendment_model->getPONO();
$this->global['pageTitle'] = 'Siddharth : Amendment Purchase Order';
$this->loadviews('amendmentpo',$this->global, NULL);
}
function amendmentpolisting()
{
$this->global['pageTitle'] = 'Siddharth : Amendment Purchase Order';
$data['POlisiting']=$this->amendment_model->getPOlist();
//echo "From CON.</br>";
//print_r($data);
$this->loadviews('amendmentpolisting',$this->global,$data);
}
function pageNotFound()
{
$this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}