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"]); $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); $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.=" ".$SNo." ". $ReqNo." ".$Reqedby." ".$ReqDate." ".$SupplierID." ".$MaterialCode." ".$Description." ".$UOM." ".$Quantity." ".$Rate." ".$Workstatus." "; } 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 ""; } // 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'); $BudgetType = $this->input->post('Budget'); $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,'BudgetType'=>$BudgetType); $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; /*---------*/ // $logpo =array('PONO'=>$PONO,'Date'=>$PODate,'POType'=>$POType,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'SupplierID'=>$SupplierID,'LineItemNos'=>$LineItemNo); // $addlog= $this->purchaseorder_model->newlogpo($logpo); /*---------*/ 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'); $newsup=$this->input->post('newsup'); $newSupId = split("[ - ]+", $newsup); $POdt =$this->input->post('PODate'); $PODate = $this->getDateformat($POdt); /*-----------------------------------*/ $b4supplier=$this->input->post('b4supplier'); $b4date=$this->input->post('b4podate'); $b4podate = $this->getDateformat($b4date); /*-----------------------------------*/ $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'); $BudgetType = $this->input->post('Budget'); $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,'BudgetType'=>$BudgetType); $POMaster = $this->purchaseorder_model->updatePOMaster($PONO,$POList); $LineItemStatus = REQITEM_NEW; if($PODate != $b4podate ) { $logpo =array('PONO'=>$PONO,'LineItemNos'=>'-','UpdateBy'=>$updatedBy,'UpdatedOn'=>$updateddt,'oldValue'=>$b4podate,'newValue'=>$PODate,'entity'=>'PO DateChanged'); $this->purchaseorder_model->insertlogpo($logpo); } if(!empty($newSupId[0] )) { if($newSupId[0] != $b4supplier) { //$newsupname = $newSupId[0].'-'.$newSupId[1]; //echo $newsup;die; $logpo =array('PONO'=>$PONO,'LineItemNos'=>'-','UpdateBy'=>$updatedBy,'UpdatedOn'=>$updateddt,'oldValue'=>$b4supplier,'newValue'=>$newsup,'entity'=>'Supplier Changed'); $this->purchaseorder_model->insertlogpo($logpo); } } for ($i = 1; $i <= $RowCount; $i++) { $MaterialCode = $this->input->post('materialCode'.$i); $Quantity = $this->input->post('quantity'.$i); /*-----------------------------------*/ $b4qty=$this->input->post('b4qty'.$i); $b4rate=$this->input->post('b4rate'.$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); /*------------------------------*/ //if($MaterialCode!= ''){ $ReqDetails = array('Quantity'=>$Quantity,'UpdatedBy'=>$updatedBy,'UpdatedOn'=>$updateddt); //print_r($ReqDetails); $this->purchaseorder_model->updateReqDetails($Reqnumber,$MaterialCode,$ReqDetails); // } /*------------------------------*/ /*---------start---------------------*/ // if(($PODate != $b4podate )||($SupplierID != $b4supplier) || ($itemRate!=$b4rate) || // ($Quantity != $b4qty )) // { // $logpo =array('UpdateBy'=>$updatedBy,'UpdatedOn'=>$updateddt); // $this->purchaseorder_model->updatelogpo($MaterialCode,$POLineItemNo,$logpo); // } if($Quantity != $b4qty) { $logpo =array('PONO'=>$PONO,'LineItemNos'=>$POLineItemNo,'UpdateBy'=>$updatedBy,'UpdatedOn'=>$updateddt,'oldValue'=>$b4qty,'newValue'=>$Quantity,'entity'=>'Quantity Changed'); $this->purchaseorder_model->insertlogpo($logpo); } if($itemRate != $b4rate) { $logpo =array('PONO'=>$PONO,'LineItemNos'=>$POLineItemNo,'UpdateBy'=>$updatedBy,'UpdatedOn'=>$updateddt,'oldValue'=>$b4rate,'newValue'=>$itemRate,'entity'=>'Rate Changed'); $this->purchaseorder_model->insertlogpo($logpo); } /*----------end--------------------*/ $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 uploadfile() { $bill= $this->input->post('param1'); $oldfile= $this->input->post('param2'); if(!empty($_FILES['file']['name'])) { $Picture = $this->add(); } $uploadfile = $this->purchaseorder_model->updatefile($bill,$Picture,$oldfile); if($uploadfile > 0){ echo "file updated successfully!"; } else{ echo "file not updated!"; } } function add() { $picture = ''; if(!empty($_FILES['file']['name'])) { $config['upload_path'] = 'uploads/BillFiles/'; $config['allowed_types'] = 'docx|pdf|doc|png|jpg'; $config['file_name'] = $_FILES['file']['name']; //print_r($config) ; //Load upload library and initialize configuration $this->load->library('upload',$config); $this->upload->initialize($config); if($this->upload->do_upload('file')) { $uploadData = $this->upload->data(); $picture = $uploadData['file_name']; } else { $error = array('error' => $this->upload->display_errors()); $picture = ''; } } else { $picture = ''; } return $picture ; } /*-----------------------------------*/ function pageNotFound() { $this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found'; $this->loadViews("404", $this->global, NULL, NULL); } } ?>