siddharth_application/application/controllers/servicepurchaseorder.php
2017-07-25 10:02:09 +05:30

409 lines
15 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();
$this->loadViews("serviceporeport", $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);
//print_r($data['PO']);
$this->loadViews("statusofservicepurchaseorder", $this->global,$data,Null);
}
function getPODetails()
{
$PONO = $this->input->post('id');
$result = $this->purchaseorder_model->GetPODetailforBillingServicePO($PONO);
$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');
$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';
$CostCode = $this->input->post('id');
$ReqType = $_GET['ReqType'];
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$Year = $dt->format('Y');
$this->load->model('purchaseorder_model');
$result = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode,$Year,$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 = '';
}
$PaymentTerms=$this->input->post('PaymentTerms');
$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 );
$POMaster = $this->purchaseorder_model->addPOMaster($POList);
$PONO = '';
if(count($POMaster)>0)
{
$PONO = $POMaster[0]['PONO'];
}
// PO Line Items
$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);
$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")
{
$POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'CostCenterCode'=>$CostCenter,'ServiceFrequency'=>$ServiceFrequency,'ServiceMaterialDescription'=>$ItemDescription);
//print_r($POLineItemList);
//die();
$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;
}
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 = '';
}
$PaymentTerms=$this->input->post('PaymentTerms');
$Payableat=$this->input->post('PayableAT');
$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 );
$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);
$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)
{
$POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$Reqnumber,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$updatedBy,'CreatedDate'=>$updateddt,'CostCenterCode'=>$CostCenter,'ServiceFrequency'=>$ServiceFrequency,'ServiceMaterialDescription'=>$ItemDescription);
$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);
$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 'Successfully updated the Service Purchase Order';
}
function pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}
?>