diff --git a/application/config/database.php b/application/config/database.php index fdb77492..a1ab5db4 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -47,18 +47,22 @@ $active_group = 'default'; $active_record = TRUE; -// old DB -// $db['default']['hostname'] = '52.172.253.20'; + +// $db['default']['hostname'] = 'localhost'; // $db['default']['username'] = 'kasiram9_prod'; // $db['default']['password'] = 'sia!1234'; // $db['default']['database'] = 'kasiram9_SIAPROD'; -// new DB $db['default']['hostname'] = '119.18.54.85'; $db['default']['username'] = 'venbaehn_sia'; $db['default']['password'] = 'gmjGKp8DyyxqnSc'; $db['default']['database'] = 'venbaehn_sia'; +// $db['default']['hostname'] = 'vprodb1.mysql.database.azure.com'; +// $db['default']['username'] = 'dbroot'; +// $db['default']['password'] = 'root@DB23'; +// $db['default']['database'] = 'sia_prod'; + $db['default']['dbdriver'] = 'mysqli'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; diff --git a/application/controllers/emergencypurchaseorder.php b/application/controllers/emergencypurchaseorder.php index 648a815e..3a76a553 100644 --- a/application/controllers/emergencypurchaseorder.php +++ b/application/controllers/emergencypurchaseorder.php @@ -271,7 +271,7 @@ function add($pathname) { //echo "t54"; - log_message('error'," Service Emr-po FNS."); + //die(); @@ -379,7 +379,6 @@ function add($pathname) if(count($Req)>0) { $RegNo = $Req[0]['ReqNo']; - log_message('error'," Service Emr-po Requistion Number. ".$RegNo); } @@ -391,7 +390,6 @@ function add($pathname) if(count($POMaster)>0) { $PONO = $POMaster[0]['PONO']; - log_message('error'," Service Emr-po Number. ".$PONO); } $RegDetailsStatus=REQITEM_POCREATED; @@ -447,7 +445,6 @@ function add($pathname) if(count($ReqDetQuery)>0) { $ItemNo = $ReqDetQuery[0]['ItemNo']; - log_message('error'," Service Emr-po Requistion Lineitem . ".$ItemNo); } $POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$RegNo,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'CostCenterCode'=>$CostCenter,'ServiceMaterialDescription'=>$ServiceMaterialDescription,'ServiceFrequency'=>$ServiceFrequency,'Per'=>$Per,'ItemNo'=>$ItemNo); @@ -458,7 +455,6 @@ function add($pathname) if(count($POLineItem)>0) { $LineItemNo = $POLineItem[0]['LineItemNo']; - log_message('error'," Service Emr-po Lineitem . ".$LineItemNo); } if(trim($POType) == SERVICE ) { @@ -466,7 +462,6 @@ function add($pathname) $ServiceTaxList = array('LineItemNo'=>$LineItemNo, 'CGST'=>$Cgst,'After_CGST'=>$AfterCgst,'SGST'=>$Sgst,'After_SGST'=>$AfterSgst,'IGST'=>$Igst,'After_IGST'=>$AfterIgst,'otherallowance'=>$OtherAmt,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt); $ServiceTax = $this->purchaseorder_model->addServiceTax($ServiceTaxList); - log_message('error'," Service Emr-po Tax ID . ".$ServiceTax); } } @@ -499,12 +494,11 @@ $prefile =array(); $pathname = 'browseFiles'.$i; - log_message('error'," Service Emr-po Browse File Path Name ".$pathname); + if(!empty($_FILES[$pathname]['name'])) { $files = str_replace(" ","",$_FILES[$pathname]['name']); - log_message('error'," Service Emr-po File Name ".$files); $fcount = 0; @@ -527,8 +521,7 @@ $prefile =array(); if($fcount == 0) { $Picture = $this->add($pathname); - //echo $Picture; - log_message('error'," Revenue Emr-po File status ".$Picture); + //echo $Picture; $arr[] = array($Picture); } @@ -555,8 +548,7 @@ $prefile =array(); { $myfile = array('FilePath'=>$filename,'PONO'=>$PONO); - $fileno = $this->purchaseorder_model->fileupload($myfile); - log_message('error'," Revenue Emr-po File Number.".$fileno); + $this->purchaseorder_model->fileupload($myfile); } @@ -572,7 +564,6 @@ $prefile =array(); echo ""; - log_message('error'," Service Emr-po successfully created. ".$PONO."-".$POStatus); redirect('purchaseorder/PurchaseOrderList','refresh'); } @@ -581,7 +572,6 @@ $prefile =array(); // echo 'Emergency Service Purchase Order Created Successfully!The PO NO Is: '.$PONO; echo ""; - log_message('error'," Service Emr-po successfully created. ".$PONO."-".$POStatus); redirect('purchaseorder/PurchaseOrderList','refresh'); } @@ -594,25 +584,25 @@ $prefile =array(); //This used to Create Revenue Emergency Purchase Order function addNewRevenuePurchaseOrder() { - log_message('error'," Revenue Emr-po FNS."); - - $txtspl=$this->input->post('txtSpecial'); - // echo "\n *** txtspl".$txtspl; + + + $txtspl=$this->input->post('txtSpecial'); + + $POdt =$this->input->post('PODate'); $PODate = $this->getDateformat($POdt); $SupplierID = $this->input->post('drpSupplier'); $DeliveryAddr = $this->input->post('DeliveryAddr'); $dt = $this->input->post('Deliverydt'); - $DeliveryOption = $this->input->post('DateRange'); - // echo "\n DeliveryOption ".$DeliveryOption; - if($DeliveryOption==1){ - $Deliverydt = ''; - $DeliverySchedule = $this->input->post('Scheduleby'); - } - else{ - $Deliverydt = $this->getDateformat($dt); - $DeliverySchedule = ''; - } + $DeliveryOption = $this->input->post('DateRange'); + if($DeliveryOption==1){ + $Deliverydt = ''; + $DeliverySchedule = $this->input->post('Scheduleby'); + } + else{ + $Deliverydt = $this->getDateformat($dt); + $DeliverySchedule = ''; + } $Modeofshipment=$this->input->post('emergmodeofshipment'); $supplierreference=$this->input->post('emergsupplierreference'); @@ -621,23 +611,30 @@ $prefile =array(); $fincap=$this->input->post('emergfincap'); $revenuetype=$this->input->post('PoTypeOptions'); $insurancestatus=$this->input->post('insuranceStatus'); - if($insurancestatus == 1) $insuranceno=$this->input->post('insuranceNo'); - else $insuranceno=""; - - $CostCenterName = $this->input->post('CostCenterName'); + if($insurancestatus == 1){ + $insuranceno=$this->input->post('insuranceNo'); + }else{ + $insuranceno=""; + } + $CostCenterName = $this->input->post('CostCenterName'); $POType = $this->input->post('POType'); $PoRange = $this->input->post('txtPoRange'); $SpcialInstruction = $this->input->post('txtSpcialInstruction'); - $RequistionComments = "Created Emergency Revenue PO"; + $RequistionComments = "Created Emergency Revenue PO"; $TotalOrderValueSummary = $this->input->post('txtTotalOrderValueSummary'); - if($txtspl==0) $POStatus=REQITEM_Emergency_PO_CREATED; - else $POStatus=SPECIAL_PO; - - // echo "\n *** POStatus ".$POStatus; + if($txtspl==0) + { + $POStatus=REQITEM_Emergency_PO_CREATED; + } + else + { + $POStatus=SPECIAL_PO; + } + //$POStatus = $this->input->post('TextStatus'); - $RequestedBy = $this->input->post('drpDepartment'); +$RequestedBy = $this->input->post('drpDepartment'); $CreateBy = $this->session->userdata ( 'userId' ); // $RowCount = $this->input->post('TextRowCount'); @@ -649,56 +646,62 @@ $prefile =array(); // $DeletedRow = $this->input->post('TextDeletedRowCount'); $DeletedRow = $this->input->post('txtDeletedRow1'); - $splRow = $this->input->post('splrow'); + + + + $splRow = $this->input->post('splrow'); + // echo $DeletedRow; - $ReqStatus = REQITEM_Emergency_PO_CREATED; - $Local_Interstate=$this->input->post('Range'); + $ReqStatus = REQITEM_Emergency_PO_CREATED; + $Local_Interstate=$this->input->post('Range'); $comma_separated = explode(':', $DeletedRow); $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createddt = $dt->format('Y-m-d H:i:s'); - $PaymentTerms=$this->input->post('PaymentMethod'); + $PaymentTerms=$this->input->post('PaymentMethod'); $OtherPayment=$this->input->post('Otherpayment'); - if($POStatus==SPECIAL_PO) $Qualitycheck=$this->input->post('txtQuality'); - else $Qualitycheck=1; - + if($POStatus==SPECIAL_PO) + { + $Qualitycheck=$this->input->post('txtQuality'); + } + + else + { + $Qualitycheck=1; + } + + + //add requistion - $Request = array('ReqType'=>$POType, 'RequestedDept'=>$RequestedBy,'CostCenterCode'=>$CostCenterName,'Status'=>$ReqStatus,'Comments'=>$RequistionComments,'ReqDate'=>$createddt,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy); - // print_r($Request); - // echo "\n *** "; + $Request = array('ReqType'=>$POType, 'RequestedDept'=>$RequestedBy,'CostCenterCode'=>$CostCenterName,'Status'=>$ReqStatus,'Comments'=>$RequistionComments,'ReqDate'=>$createddt,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy); - $Req = $this->requistion_model->addRequistion($Request); - //$RegNo='01'; - $RegNo=''; - if(count($Req)>0) - { - $RegNo = $Req[0]['ReqNo']; - log_message('error'," Revenue Emr-po Req Raised Number".$RegNo); - } - // echo "i HAVE".$RegNo; - // die(); + $Req = $this->requistion_model->addRequistion($Request); + + $RegNo=''; + if(count($Req)>0) + { + $RegNo = $Req[0]['ReqNo']; + } // PO Master $POList = array('SupplierID'=>$SupplierID, 'TotalOrderValue'=>$TotalOrderValueSummary,'PODate'=>$PODate,'Status'=>$POStatus,'DeliverySchedule'=>$DeliverySchedule,'DeliveryOption'=>$DeliveryOption,'PORange'=>$Local_Interstate,'ServiceDescription'=>$SpcialInstruction,'CreatedBy'=>$CreateBy,'DeliveryAddress'=>$DeliveryAddr,'DeliveryDate'=>$Deliverydt,'CreatedDate'=>$createddt,'PaymentTerms'=>$PaymentTerms,'POType'=>$POType,'CapitalRange'=>$Local_Interstate,'PaymentOtherDescription'=>$OtherPayment,'Mode_Of_Shipment'=>$Modeofshipment,'Supplier_Offer_No'=>$supplieroffno,'Supplier_Reference'=>$supplierreference,'Other_Reference'=>$otherreference,'InsuranceNumber'=>$insuranceno,'InsuranceStatus'=>$insurancestatus,'Fincap'=>$fincap,'POSubType'=>$revenuetype,'IsQualityChkReqired'=>$Qualitycheck,'BudgetType'=>$BudgetType); - //print_r($POList); - //echo "\n *** "; - $POMaster = $this->purchaseorder_model->addPOMaster($POList,$POType,$revenuetype); + //print_r($POList); + $POMaster = $this->purchaseorder_model->addPOMaster($POList,$POType,$revenuetype); - $PONO = ''; - if(count($POMaster)>0) - { - $PONO = $POMaster[0]['PONO']; - log_message('error'," Revenue Emr-po Number .".$PONO); - } - //echo $PONO; - // PO Line Items - $RegDetailsStatus=REQITEM_POCREATED; - $LineItemStatus = REQITEM_NEW; + $PONO = ''; + if(count($POMaster)>0) + { + $PONO = $POMaster[0]['PONO']; + } + //echo $PONO; + // PO Line Items + $RegDetailsStatus=REQITEM_POCREATED; + $LineItemStatus = REQITEM_NEW; - for ($i = 1; $i <= $RowCount; $i++) + for ($i = 1; $i <= $RowCount; $i++) { $MaterialCode = $this->input->post('materialCode'.$i); @@ -718,7 +721,7 @@ $prefile =array(); $FreightType = $this->input->post('FreightType'.$i); $FreightValue = $this->input->post('FreightVal'.$i); $AfterFreightValue = $this->input->post('AfterFreightVal'.$i); - $NOOfTrip = $this->input->post('NoOfTrip'.$i); + $NOOfTrip = $this->input->post('NoOfTrip'.$i); $InsuranceValue = $this->input->post('Insval'.$i); $TotalOrderValue = $this->input->post('TotalOrderValue'.$i); $revenuedescription = $this->input->post('service_description'.$i); @@ -743,196 +746,231 @@ $prefile =array(); } } - } - if($SkipInsert == "False") + } + if($SkipInsert == "False") { - //add requistion details - $ReqDetails = array('ReqNo'=>$RegNo, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Status'=>$RegDetailsStatus,'UpdatedBy'=>$CreateBy,'UpdatedOn'=>$createddt); - // print_r($ReqDetails); - $ReqDetQuery = $this->requistion_model->addRequistionDetails($ReqDetails); - log_message('error'," Revenue Emr-po RequistionDetails count . ".count($ReqDetQuery)." ReqNo".isset($ReqDetQuery[0]['ItemNo'])?$ReqDetQuery[0]['ItemNo']:" -- "); - + //add requistion details + $ReqDetails = array('ReqNo'=>$RegNo, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Status'=>$RegDetailsStatus,'UpdatedBy'=>$CreateBy,'UpdatedOn'=>$createddt); + + + $ReqDetQuery = $this->requistion_model->addRequistionDetails($ReqDetails); + $POLineItemList = array('PONO'=>$PONO, 'ReqNo'=>$RegNo,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'Status'=>$LineItemStatus,'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt,'CostCenterCode'=>$CostCenter,'Per'=>$per,'ServiceMaterialDescription'=>$revenuedescription); //print_r($POLineItemList); - //echo "\n *** "; $POLineItem = $this->purchaseorder_model->addPOLineItem($POLineItemList); - - //$LineItemNo = 'LI000'; + $LineItemNo = ''; if(count($POLineItem)>0) { $LineItemNo = $POLineItem[0]['LineItemNo']; - log_message('error'," Revenue Emr-po Line Item Number . ".$LineItemNo); } //echo $LineItemNo; - /*----------------------------*/ - // $logpo =array('PONO'=>$PONO,'Date'=>$PODate,'POType'=>$POType,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'SupplierID'=>$SupplierID,'LineItemNos'=>$LineItemNo); + /*----------------------------*/ + // $logpo =array('PONO'=>$PONO,'Date'=>$PODate,'POType'=>$POType,'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'Rate'=>$itemRate,'SupplierID'=>$SupplierID,'LineItemNos'=>$LineItemNo); + + // $logaddpo = $this->purchaseorder_model->newlogpo($logpo); + - // $logaddpo = $this->purchaseorder_model->newlogpo($logpo); /*----------------------------*/ - - + + if(trim($POType) == REVENUE ) { - // echo 'Success'; - $RevenueTaxList = array('LineItemNo'=>$LineItemNo, 'DiscountType'=>$DiscountType,'DiscountValue'=>$DiscountValue,'AfterDiscount'=>$AfterDiscount,'PackagingType'=>$PackagingType,'PackagingValue'=>$PackagingValue,'PackagingCalulatedOn'=>$PackagingOption,'AfterPackagingValue'=>$AfterPackagingValue,'FreightType'=>$FreightType, 'FreightValue'=>$FreightValue,'AfterFreightValue'=>$AfterFreightValue,'Insurance'=>$InsuranceValue,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt, 'CGST'=>$Cgst,'AfterCGST'=>$AfterCgst,'SGST'=>$Sgst,'AfterSGST'=>$AfterSgst,'IGST'=>$Igst,'AfterIGST'=>$AfterIgst,'NoOfTrip'=>$NOOfTrip); - //print_r($RevenueTaxList); - //echo "\n"; - $RevenueList = $this->purchaseorder_model->addRevenueTax($RevenueTaxList); - //echo 'Revenue tax Success'; - log_message('error'," Revenue Emr-po tax Successfully . "); + // echo 'Success'; + $RevenueTaxList = array('LineItemNo'=>$LineItemNo, 'DiscountType'=>$DiscountType,'DiscountValue'=>$DiscountValue,'AfterDiscount'=>$AfterDiscount,'PackagingType'=>$PackagingType,'PackagingValue'=>$PackagingValue,'PackagingCalulatedOn'=>$PackagingOption,'AfterPackagingValue'=>$AfterPackagingValue,'FreightType'=>$FreightType, 'FreightValue'=>$FreightValue,'AfterFreightValue'=>$AfterFreightValue,'Insurance'=>$InsuranceValue,'TotalValue'=>$TotalOrderValue, 'CreatedBy'=>$CreateBy,'CreatedDate'=>$createddt, 'CGST'=>$Cgst,'AfterCGST'=>$AfterCgst,'SGST'=>$Sgst,'AfterSGST'=>$AfterSgst,'IGST'=>$Igst,'AfterIGST'=>$AfterIgst,'NoOfTrip'=>$NOOfTrip); + //print_r($RevenueTaxList); + $RevenueList = $this->purchaseorder_model->addRevenueTax($RevenueTaxList); + //echo 'Revenue tax Success'; } - } + } } - if($txtspl==1 || $txtspl==2) - { - $PONOigr = $PONO; + if($txtspl==1 || $txtspl==2) + { + + //secho "cwwe"; + //die(); + + $PONOigr = $PONO; + + //echo $PONOigr; + //die(); + //IGR Data Entry + //$DeliveryChellanOrInvoiceNo = $this->input->post('ChallanInvNo'); + + $DeliveryChellanInvoiceNo=$this->input->post('ChallanInvNo'); - //IGR Data Entry - //$DeliveryChellanOrInvoiceNo = $this->input->post('ChallanInvNo'); + $DeliveryChellan = $this->input->post('ChallanInvDate'); + $DeliveryChellanDate = $this->getDateformat($DeliveryChellan); + + $MaterialReceive = $this->input->post('MRC'); + $MaterialReceivedate = $this->getDateformat($MaterialReceive); - $DeliveryChellanInvoiceNo=$this->input->post('ChallanInvNo'); - - $DeliveryChellan = $this->input->post('ChallanInvDate'); - $DeliveryChellanDate = $this->getDateformat($DeliveryChellan); - - $MaterialReceive = $this->input->post('MRC'); - $MaterialReceivedate = $this->getDateformat($MaterialReceive); + $Vehicle = $this->input->post('VehicleNo'); + $Courier = $this->input->post('CourierNo'); + - $Vehicle = $this->input->post('VehicleNo'); - $Courier = $this->input->post('CourierNo'); - + $CreatedBy = $this->session->userdata('userId'); - $CreatedBy = $this->session->userdata('userId'); - - $Remarksmrir='Emergency PO without Quality Check'; - //$Remarks = $this->input->post('Remarks'); - //$RowCount = $this->input->post('TextRowCount'); - //echo $RowCount; - $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); - $createddt = $dt->format('Y-m-d H:i:s'); - - $IGRStatus = IGR_CREATED; + $Remarksmrir='Emergency PO without Quality Check'; + //$Remarks = $this->input->post('Remarks'); + //$RowCount = $this->input->post('TextRowCount'); + //echo $RowCount; + $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); + $createddt = $dt->format('Y-m-d H:i:s'); + + $IGRStatus = IGR_CREATED; - $igr = array(); - $paymentstatus = NO_PAIDIGR; - $igr = array('PONO'=>$PONO,'VehicleNo'=>$Vehicle,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanInvoiceNo,'DeliveryChellanDate'=>$DeliveryChellanDate,'MaterialRcvdDate'=>$DeliveryChellanDate,'CourierNo'=>$Courier,'IGRStatus'=>$IGRStatus,'CreatedBy'=>$CreatedBy,'CreatedDate' =>$createddt,'MaterialRcvdDate'=>$MaterialReceivedate,'Paymentstatus'=>$paymentstatus); + $igr = array(); + $paymentstatus = NO_PAIDIGR; + $igr = array('PONO'=>$PONO,'VehicleNo'=>$Vehicle,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanInvoiceNo,'DeliveryChellanDate'=>$DeliveryChellanDate,'MaterialRcvdDate'=>$DeliveryChellanDate,'CourierNo'=>$Courier,'IGRStatus'=>$IGRStatus,'CreatedBy'=>$CreatedBy,'CreatedDate' =>$createddt,'MaterialRcvdDate'=>$MaterialReceivedate,'Paymentstatus'=>$paymentstatus); - //print_r($igr); - //echo "\n"; + //print_r($igr); - $igrM = $this->inwardgateregister_model->addigrM($igr); - //$IGRNO = 'igr001'; - $IGRNO = ''; - if(count($igrM)>0) - { - foreach ($igrM as $key ) - { - $IGRNO=$key->IGRNO; - log_message('error'," Revenue Emr-po IGR Number.".$IGRNO); - } - } - if($Qualitycheck==0) - { + $igrM = $this->inwardgateregister_model->addigrM($igr); - $mrirmastervalues = array('MRIRStatus'=>MRIR_APPROVED,'IGRNO'=>$IGRNO,'PONO'=>$PONO,'CreatedBy'=>$CreatedBy,'Createdon'=>$createddt,'Remarks'=>$Remarksmrir); + + + + + + + + + + + + + + + + $IGRNO = ''; + if(count($igrM)>0) + { + foreach ($igrM as $key ) + { + $IGRNO=$key->IGRNO; + } + } + // echo $IGRNO; + + + + + + + + + if($Qualitycheck==0) + { + + + $mrirmastervalues = array('MRIRStatus'=>MRIR_APPROVED,'IGRNO'=>$IGRNO,'PONO'=>$PONO,'CreatedBy'=>$CreatedBy,'Createdon'=>$createddt,'Remarks'=>$Remarksmrir); - $mrirmaster = $this->mrir_model->master_mrir($mrirmastervalues); + $mrirmaster = $this->mrir_model->master_mrir($mrirmastervalues); - // $MRIRNO = 'MRIR001'; - $MRIRNO = ''; + $MRIRNO = ''; - if(count($mrirmaster)>0) - { - foreach ($mrirmaster as $key ) { + if(count($mrirmaster)>0) + + { + foreach ($mrirmaster as $key ) { - $MRIRNO=$key->MRIRNo; } - log_message('error'," Revenue Emr-po MRIR Number.".$MRIRNO); - } + $MRIRNO=$key->MRIRNo; } + } - for ($i = 1; $i <= $RowCount; $i++) - { + for ($i = 1; $i <= $RowCount; $i++) + { - $MaterialCode = $this->input->post('materialCode'.$i); - $Quantity = $this->input->post('quantity'.$i); - $Remarked = "Special PO Without Quality Check"; - $MRIRStatus=MRIR_APPROVED; + $MaterialCode = $this->input->post('materialCode'.$i); + $Quantity = $this->input->post('quantity'.$i); + + $Remarked = "Special PO Without Quality Check"; + + $MRIRStatus=MRIR_APPROVED; - //this array to store the value in child table.. - $mrirdetailvalues = array('MRIRNO'=>$MRIRNO,'MaterialCode'=>$MaterialCode,'ActualQuantityReceived'=>$Quantity,'Remarks'=>$Remarked,'MRIRStatus'=>$MRIRStatus); + //this array to store the value in child table.. + $mrirdetailvalues = array('MRIRNO'=>$MRIRNO,'MaterialCode'=>$MaterialCode,'ActualQuantityReceived'=>$Quantity,'Remarks'=>$Remarked,'MRIRStatus'=>$MRIRStatus); - // print_r($mrirdetailvalues); - // echo 'MRIRItemNo001'; - $mrirdetails = $this->mrir_model->detail_mrir($mrirdetailvalues); - log_message('error'," Revenue Emr-po MRIR Item Number.".$mrirdetails[0]['MRIRItemNo']); - $getAvailableqty = $this->mrir_model->getItemQuantityFromStock(trim($MaterialCode)); - // print_r($getAvailableqty); - // echo "\n get available Qty"; - if(count($getAvailableqty)>0) + + //print_r($mrirdetailvalues); + //die(); + + $mrirdetails = $this->mrir_model->detail_mrir($mrirdetailvalues); + + + + + + $getAvailableqty = $this->mrir_model->getItemQuantityFromStock(trim($MaterialCode)); + + if(count($getAvailableqty)>0) { $avlQty = $getAvailableqty[0]['Quantity']; } - $updatStock = array('Quantity'=>($Quantity+$avlQty),'Status'=>'0','UpdatedOn'=>$createddt,'UpdatedBy'=>$CreatedBy,'Remarks'=>'Stock added for '. $MRIRNO); - // print_r($updatStock); - // echo "\n updat Stock"; - $this->mrir_model->UpdateStock($updatStock,trim($MaterialCode)); + $updatStock = array('Quantity'=>($Quantity+$avlQty),'Status'=>'0','UpdatedOn'=>$createddt,'UpdatedBy'=>$CreatedBy,'Remarks'=>'Stock added for '. $MRIRNO); + + $this->mrir_model->UpdateStock($updatStock,trim($MaterialCode)); - } + } - } - - $IGRItemStatus = REQITEM_NEW; + } - for ($i = 1; $i <= $RowCount; $i++) - { + + + $IGRItemStatus = REQITEM_NEW; + + + for ($i = 1; $i <= $RowCount; $i++) + { - $MaterialCode = trim($this->input->post('materialCode'.$i)); + $MaterialCode = trim($this->input->post('materialCode'.$i)); - $QuantityAsPerInvoice = $this->input->post('quantity'.$i); + $QuantityAsPerInvoice = $this->input->post('quantity'.$i); - $OrderedQuantity = $this->input->post('quantity'.$i); + $OrderedQuantity = $this->input->post('quantity'.$i); - $ReceivedQty = $this->input->post('AQuantity'.$i); + $ReceivedQty = $this->input->post('AQuantity'.$i); - $emergencyitemcode = $this->input->post('emergencyitemcode'); + $emergencyitemcode = $this->input->post('emergencyitemcode'); - $PendingQty = 0; - //echo $QuantityAsPerInvoice; - //echo $PendingQty.'ReceivedQty'.$ReceivedQty; - //echo ' '; + $PendingQty = 0; + //echo $QuantityAsPerInvoice; + //echo $PendingQty.'ReceivedQty'.$ReceivedQty; + //echo ' '; - if(strlen($QuantityAsPerInvoice)>0 && $QuantityAsPerInvoice != '0') - { - $Remarks = "Special PO Created"; - $ItemStatus = ''; - //if($QuantityAsPerInvoice == $OrderedQuantity) + if(strlen($QuantityAsPerInvoice)>0 && $QuantityAsPerInvoice != '0') + { + $Remarks = "Special PO Created"; + $ItemStatus = ''; + //if($QuantityAsPerInvoice == $OrderedQuantity) - if($PendingQty == 0.00 ) - { - $ItemStatus = IGR_CREATED; - } - else - { - $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; - } + if($PendingQty == 0.00 ) - $CreatedBy = $this->session->userdata('userId'); + { + $ItemStatus = IGR_CREATED; + } + else + { + $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; + } + + $CreatedBy = $this->session->userdata('userId'); $igrDetails = array('IGRNO'=>$IGRNO,'MaterialCode'=>$MaterialCode,'QuantityAsPerInvoice'=>$QuantityAsPerInvoice,'Remarks'=>$Remarks,'IGRItemStatus'=>$IGRItemStatus,'CreatedBy'=>$CreatedBy,'CreatedDate'=>$createddt); @@ -940,52 +978,52 @@ $prefile =array(); //print_r($igrDetails); - //echo "\n **** "; + + $igrD = $this->inwardgateregister_model->addigrD($igrDetails); - //print_r($igrD); - //* ================================================== * / - //$IGRItemNo = 'IGRItemNo001'; + + +//print_r($igrD); +//* ================================================== * / $IGRItemNo = ''; foreach($igrD as $value) { $IGRItemNo = $value->IGRItemNo; - log_message('error'," Revenue Emr-po IGR Item Number.".$IGRItemNo); } - //echo $IGRItemNo; +//echo $IGRItemNo; $MaterialstockHistoryadd= array('Ref_No'=>$IGRItemNo,'MaterialCode'=>$MaterialCode,'Transaction_type'=>'Add','Ref_Type'=>'IGR','SupplierID'=>$SupplierID,'Quantity'=>$QuantityAsPerInvoice,'ItemValue'=>$itemRate,'CreatedBy'=>$CreatedBy,'CreatedOn'=>$createddt); - $MStockHistory = $this->inwardgateregister_model->addMaterialStockHistory($MaterialstockHistoryadd); - //print_r($MaterialstockHistoryadd); - log_message('error'," Revenue Emr-po Material Stock History added. count ".count($MStockHistory)); - //*=====================================================*/ + $this->inwardgateregister_model->addMaterialStockHistory($MaterialstockHistoryadd); + //*=====================================================*/ - //*===================================================*/ + //*===================================================*/ - $get_pre_qty= $this->inwardgateregister_model->get_CurrentQty($MaterialCode); - $av_qty=0; - if(!empty($get_pre_qty)) - { - foreach($get_pre_qty as $gt) - { - $av_qty=$gt->Current_stock; - } - } + $get_pre_qty= $this->inwardgateregister_model->get_CurrentQty($MaterialCode); + $av_qty=0; + if(!empty($get_pre_qty)) + { + foreach($get_pre_qty as $gt) + { + $av_qty=$gt->Current_stock; + } + } - $currentav_qty= $QuantityAsPerInvoice+$av_qty; + $currentav_qty= $QuantityAsPerInvoice+$av_qty; - $current_qty= array('Current_stock'=>$currentav_qty); - // print_r($current_qty); - // echo "\n ****"; - $mMaster = $this->inwardgateregister_model->addmaterialmaster($current_qty,$MaterialCode); - log_message('error'," Revenue Emr-po Material Master Qty added.".$mMaster); + $current_qty= array('Current_stock'=>$currentav_qty); - //*==================================================*/ + $this->inwardgateregister_model->addmaterialmaster($current_qty,$MaterialCode); + + + + + //*==================================================*/ @@ -998,115 +1036,123 @@ $prefile =array(); $ReceivedQuantity=$key->ReceivedQuantity; } } - $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; + $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; //echo ''; $POLineItem = array('ReceivedQuantity'=>$totalReceivedqty,'Status'=>$ItemStatus,'UpdateBY'=>$CreatedBy,'UpdatedOn'=>$createddt ); - $pod = $this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$PONO,$MaterialCode); - log_message('error'," Revenue Emr-po updating PO.sub details totalReceivedqty,Status ".$totalReceivedqty." ".$ItemStatus." ".$pod); - } - - - //$myfile = array('FilePath'=>$filename); - // $emergencyitemcode = $this->input->post('emergencyitemcode'.$i); - // ($this->input->post('materialCode'.$i)); - + $this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$PONO,$MaterialCode); } + + + //$myfile = array('FilePath'=>$filename); + // $emergencyitemcode = $this->input->post('emergencyitemcode'.$i); + // ($this->input->post('materialCode'.$i)); + +} - $counts = $this->input->post('hidecounter'); - $constants = $this->input->post('hideconstant'); + $counts = $this->input->post('hidecounter'); + $constants = $this->input->post('hideconstant'); - // $arr = []; +// $arr = []; - // for($i=1;$i<=$constants;$i++){ - // $pathname = 'browseFiles'.$i; +// for($i=1;$i<=$constants;$i++){ +// $pathname = 'browseFiles'.$i; - // if(!empty($_FILES[$pathname]['name'])) - // { - // $Picture = $this->addfile($pathname); - // //echo $Picture; - // $arr[$i] = array($Picture); - // } +// if(!empty($_FILES[$pathname]['name'])) +// { +// $Picture = $this->addfile($pathname); +// //echo $Picture; +// $arr[$i] = array($Picture); +// } - // } +// } - $arr = []; - $prefile =array(); + $arr = []; +$prefile =array(); - for($i=1;$i<=$constants;$i++) - { - $pathname = 'browseFiles'.$i; - log_message('error'," Revenue Emr-po Browse File Path Name ".$pathname); + for($i=1;$i<=$constants;$i++) + { + $pathname = 'browseFiles'.$i; - if(!empty($_FILES[$pathname]['name'])) - { + if(!empty($_FILES[$pathname]['name'])) + { - $files = str_replace(" ","",$_FILES[$pathname]['name']); - log_message('error'," Revenue Emr-po File Name ".$files); + $files = str_replace(" ","",$_FILES[$pathname]['name']); - $fcount = 0; + $fcount = 0; - foreach ($prefile as $value) - { - - if($value == $files) $fcount++; + foreach ($prefile as $value) + { + - } - - if($fcount == 0) - { - $Picture = $this->addfile($pathname); - log_message('error'," Revenue Emr-po File status ".$Picture); - $arr[] = array($Picture); - - } - - $prefile[] = $files; - - } - } - - if(!empty($arr)) + if($value == $files) { - foreach($arr as $ma) - { - - $index = 0; - $filename = null; - foreach($ma as $key=>$value) - { - $index++; - if($index == 1){ - $filename = $value; - } - } - if(!empty($filename)){ - - $myfile = array('FilePath'=>$filename,'PONO'=>$PONO,'IGRNO'=>$IGRNO); - //print_r($myfile); - $fileno = $this->purchaseorder_model->fileupload($myfile); - log_message('error'," Revenue Emr-po File Number.".$fileno); - } - - - } + + + $fcount++; + } + - } + + } + + if($fcount == 0) + { + $Picture = $this->addfile($pathname); + //echo $Picture; + $arr[] = array($Picture); + + } + + $prefile[] = $files; + + } + } + + if(!empty($arr)) + { + foreach($arr as $ma) + { + + + $index = 0; + $filename = null; + foreach($ma as $key=>$value) + { + $index++; + if($index == 1){ + $filename = $value; + } + } + if(!empty($filename)) + { + + $myfile = array('FilePath'=>$filename,'PONO'=>$PONO,'IGRNO'=>$IGRNO); + $this->purchaseorder_model->fileupload($myfile); + } + + + } + + + } - } +} - echo ""; - log_message('error'," Revenue Emr-po successfully created. ".$PONO); - redirect('purchaseorder/PurchaseOrderList','refresh'); + + + + echo ""; + redirect('purchaseorder/PurchaseOrderList','refresh'); } diff --git a/application/controllers/inwardgateregister.php b/application/controllers/inwardgateregister.php index 094a57ba..57ee2ef6 100644 --- a/application/controllers/inwardgateregister.php +++ b/application/controllers/inwardgateregister.php @@ -588,7 +588,7 @@ $prefile =array(); $IGRNO=$key->IGRNO; } } - echo $IGRNO; + //echo $IGRNO; $IGRItemStatus = REQITEM_NEW; $TotalPendingQty = ''; diff --git a/application/controllers/login.php b/application/controllers/login.php index a6b8b369..cf82d055 100644 --- a/application/controllers/login.php +++ b/application/controllers/login.php @@ -1,557 +1,610 @@ -load->model('login_model'); - $this->load->model('Zohobook_api_model','Zohobook_model'); - $this->load->helper('zohobooks_fetch_api_helper'); - } - - /** - * Index Page for this controller. - */ - public function index() - { - $this->isLoggedIn(); - } - - /** - * This function used to check the user is logged in or not - */ - function isLoggedIn() - { - $isLoggedIn = $this->session->userdata('isLoggedIn'); - - if(!isset($isLoggedIn) || $isLoggedIn != TRUE) - { - // print_r($this->session->all_userdata()); - $this->load->view('login'); - - } - else - { - redirect('/dashboard'); - } - } - - - /** - * This function used to logged in user - */ - public function loginMe() - { - $this->load->library('form_validation'); - - // $this->form_validation->set_rules('email', 'Email', 'required|valid_email|max_length[128]|xss_clean|trim'); - $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|'); - $designation=''; - $role=''; - - if($this->form_validation->run() == FALSE) - { - $this->index(); - } - else - { - $email = $this->input->post('email'); - $password = $this->input->post('password'); - - $result = $this->login_model->loginMe($email, $password); - - if(count($result) > 0) - { - - // $det= $this->login_model->Accessdep($res->EmpID); - // print_r($det); - // die(); - - foreach ($result as $res) - { - log_message('ERROR','#####loggin_name : ' . $res->FirstName); - $sessionArray = array('userId'=>$res->userId, - 'role'=>$res->roleId, - 'roleText'=>$res->role, - 'name'=>$res->FirstName, - //'Designation'=>$res->Designation, - 'DEPCode'=>$res->DEPCode, - 'HeadDept'=>$res->HeadDept, - 'depaccess'=>$this->login_model->Accessdep($res->EmpID), - 'DepartmentName'=>$res->DepartmentName, - 'EmpID' => $res->EmpID, - 'isLoggedIn' => TRUE - ); - - $this->session->set_userdata($sessionArray); - - //$role=$res->roleId; - //$designation=$res->Designation; - $DEPCode=$res->DEPCode; - - - - } - if ($DEPCode == SECURITY) - { - redirect('/Addigr'); - } - else - { - redirect('/dashboard'); - } - } - else - { - $this->session->set_flashdata('error', 'Email or password mismatch'); - redirect('login'); - - } - } - } - - /** - * This function used to load forgot password view - */ - function forgotPassword() - { - $this->load->view('forgotPassword'); - } - - - /** - * To reset password of the user (without one time code) - */ - function resetPasswordUser(){ - // echo 'hi'; - // die(); - - $mobileno = $this->input->post('phno'); - $emailid = $this->input->post('email'); - $result = $this->login_model->getuserid($mobileno,$emailid); - - if(!empty($result)){ - - $string = "abcd".rand(100000,999999)."lmnxyz"; - $string_shuffled = str_shuffle($string); - $passcode = substr($string_shuffled, 1, 6); - $password = "SIDH@".$passcode; - - $mobile = "91".$result[0]->ContactNumber; - //$msg = "Your Password is 'resico1234' sent from Resico Industries "; - $msg = "Hi " .$result[0]->FirstName. ", - \n Your password has been resetted sucessfully. - \n Please login with your new password '".$password."'"; - - $message = urlencode($msg); - - $ch=curl_init(); - curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - $output =curl_exec($ch); - curl_close($ch); - - $resetpassword = getHashedPassword($password); - - $updatepassword = $this->login_model->updatepassword($result[0]->userId,$resetpassword); - - echo ""; - redirect('/loginMe','refresh'); - } - else{ - echo ""; - redirect('/loginMe','refresh'); - } - } - - - /** - * To Get One time code to reset password of the user (ajax call) - */ - /** function getOTP() - * { - * $id = $this->input->post('id'); - * $result = $this->login_model->temp($id); - * if(!empty($result)){ - * $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - * $string_shuffled = str_shuffle($string); - * $password = substr($string_shuffled, 1, 7); - * $otp = rand(1000, 9999); - * echo "resico@".rand(1000,9999);die; - * - * //print_r($result);die; - * //$result[0]->ContactNumber; - * - * $mobile = "91".$result[0]->ContactNumber; - * //$msg = "Your Password is 'resico1234' sent from Resico Industries "; - * $msg = "Hi " .$result[0]->FirstName. ", - * \n We have generated One Time Code For You. This code used for reset your password - * \n YOUR CODE IS'".$password."'and'".$otp."'"; - * - * $message = urlencode($msg); - * // echo $mobile , $message; - * $ch=curl_init(); - * curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH"); - * curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - * $output =curl_exec($ch); - * - * //return $output; - * //print_r($output);exit(); - * curl_close($ch); - * //echo json_encode($result); - * $updateotp = $this->login_model->temp2($result[0]->userId,$otp); - * $data = $updateotp[0]->OTP; - * echo $data; - * }} - */ - - /** - * After Getting One time code - * Reset password of the user (with OTP) - */ - /** function resetPasswordConfirmUser(){ - * - * // $this->load->library('form_validation'); - * - * // $this->form_validation->set_rules('newPassword','New password','required|max_length[20]'); - * // $this->form_validation->set_rules('confirmPassword','Confirm new password','required|matches[newPassword]|max_length[20]'); - * - * $newPassword = $this->input->post('newPassword'); - * $ConfirmPassword = $this->input->post('confirmPassword'); - * - * $mobileno = $this->input->post('phno'); - * - * $da ta = $this->login_model->getuserdtl($mobileno); - * $userid = $data[0]->userId; - * $OTP = NULL; - * - * $Array = array('password'=>getHashedPassword($newPassword),'OTP'=>$OTP); - * - * $result = $this->login_model->resetpassword($Array,$userid); - * - * if($result > 0) - * { - * echo ""; redirect('login','refresh'); - * } - * else - * { - * echo ""; redirect('login','refresh'); - * } - * - * } - */ - - // start zoho API - - function zohobooks_api_fetch_all(){ - try{ - if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null) - { - // $ch=curl_init(); - $this->load->helper('zohobooks_fetch_api_helper'); - if($_GET['from'] != null && $_GET['to'] != null) - { - $date_today = $_GET['to']; - $date_yesterday = $_GET['from']; - } - else - { - $date_today = date('Y-m-d'); - $date_yesterday = date('Y-m-d',strtotime('-1 day',strtotime($date_today))); - } - $chk_acc_token_val = $this->Zohobook_model->get_data('zohobook_accesstoken','id' , 1); - $date = new DateTime($chk_acc_token_val[0]['created_at']); $date->add(new DateInterval('PT1H')); - $token = 0; - if ($date->format('Y-m-d h:i:s') > date('Y-m-d h:i:s')) { $token = $chk_acc_token_val[0]['token']; } - else { $token = generateNewToken(); $tokendata['token'] = $token; $this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken'); } - $result = getheringInvoiceDetails($date_today , $date_yesterday , $token); - // echo json_encode($result); - $headers_new = $result['headers_new']; - $res = json_decode($result['data'],true); - $inv_array = $res['invoices']; - foreach($inv_array as $inv){ - $invoice_id = $inv['invoice_id']; - if($invoice_id!==""){ - $organization_id = '655654572'; - $result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new); - $resall = json_decode($result2,true); - $res2[] = $resall['invoice']; - } - } - $insert_count = 0; - $update_count = 0; - foreach($res2 as $rs) - { - $gst_no = $rs['gst_no']; - $sku = $rs['line_items'][0]['sku']; - $invoice_number = $rs['invoice_number']; - $invoice_date = $rs['date']; - - $sql_invoice_chk = $this->Zohobook_model->ip_invoices($invoice_number , $invoice_date); - if($sql_invoice_chk <= 0) - { - $gst_no = $rs['gst_no']; - $sku = $rs['line_items'][0]['sku']; - $invoice_number = $rs['invoice_number']; - $invoice_date = $rs['date']; - $due_date = $rs['due_date']; - $item_price = $rs['line_items'][0]['rate']; - $item_order = $rs['line_items'][0]['item_order']; - $item_product_unit = $rs['line_items'][0]['unit']; - $item_name = $rs['line_items'][0]['name']; - $item_description = $rs['line_items'][0]['description']; - $item_quantity = $rs['line_items'][0]['quantity']; - // $batch_no = $rs['custom_fields'][5]['value']; - $batch_no = ""; - $invoice_time=$rs['created_time']; - $time_array = explode("T", $invoice_time); - $time_array = explode("+",$time_array[1]); - $invoice_time = $time_array[0]; - $status = $rs['status']; - - $vehicle_number = $rs['custom_field_hash']['cf_vehicle_number']; - $transport_mode =$rs['custom_field_hash']['cf_transport_mode']; - $purchase_order_date = $rs['custom_field_hash']['cf_purchase_order_date']; - $driver = $rs['custom_field_hash']['cf_driver']; - $place_of_supply = $rs['custom_field_hash']['cf_place_of_supply']; - - $cgst = $rs['taxes'][0]['tax_name']; - $sgst = $rs['taxes'][1]['tax_name']; - $cgst = $cgst[4]; - $sgst = $sgst[4]; - $cgst = $cgst.'.000'; - $getcgsttax = $this->Zohobook_model->ip_tax_rates($cgst); - if($getcgsttax) - { - $cgsttaxid = $getcgsttax[0]['tax_rate_id']; - log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst); - $cgst_data['tax_rate_percent'] = $cgst; - $getcgsttax = $this->Zohobook_model->insert($cgst_data,'ip_tax_rates'); - $cgsttaxid = $getcgsttax[0]['tax_rate_id']; - log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid); - } - - $sgst = $sgst.'.000'; - $getsgsttax = $this->Zohobook_model->ip_tax_rates($sgst); - if($getsgsttax) - { - $sgsttaxid = $getsgsttax[0]['tax_rate_id']; - log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst); - $sgst_data['tax_rate_percent'] = $sgst; - $getsgsttax = $this->Zohobook_model->insert($sgst_data,'ip_tax_rates'); - $sgsttaxid = $getsgsttax[0]['tax_rate_id']; - log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid); - } - - $item_subtotal = $rs['line_items'][0]['item_total']; - $item_tax_total = $rs['tax_total']; - $item_total = $rs['total']; - $item_sgst_amt = $rs['taxes'][1]['tax_amount']; - $item_cgst_amt = $rs['taxes'][0]['tax_amount']; - - $item_discount = 0.00; - $item_igst_amt = 0.00; - if($batch_no==""){ $batch_no = "";} - $gst_sql = $this->Zohobook_model->ip_clients($gst_no); - if($gst_sql) - { - $client_id = $gst_sql[0]['client_id']; - log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no); - $gst_no_data['client_tax_code'] = $gst_no; - $gst_sql = $this->Zohobook_model->insert($gst_no_data,'ip_clients'); - $client_id = $gst_sql[0]['tax_rate_id']; - log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id); - } - - $sku_sql = $this->Zohobook_model->ip_products($sku); - if($sku_sql) - { - $product_id = $sku_sql[0]['product_id']; - log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku); - $sku_data['product_name'] = $item_name; - $sku_data['product_description'] = $item_description; - $sku_data['sku'] = $sku; - $sku_sql = $this->Zohobook_model->insert($sku_data,'ip_products'); - $product_id = $sku_sql[0]['sku']; - log_message('error', 'sku'.$sku); - log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id); - } - - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } - $url_key = $randomString; - - $ip_invoices['user_id'] = 1; - $ip_invoices['client_id'] = $client_id; - $ip_invoices['invoice_group_id'] = 6; - $ip_invoices['invoice_status_id'] = 2; - $ip_invoices['invoice_date_created'] = $invoice_date; - $ip_invoices['invoice_time_created'] = $invoice_time; - $ip_invoices['invoice_date_due'] = $due_date; - $ip_invoices['invoice_number'] = $invoice_number; - $ip_invoices['invoice_url_key'] = $url_key; - $ip_invoices['receivedstatus'] = 'ST066'; - $ip_invoices['credit_status'] = 0; - $invoice_insert_id = $this->Zohobook_model->insert($ip_invoices,'ip_invoices'); - if($invoice_insert_id) - log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id); - else - log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id); - - $ip_invoice_items['invoice_id'] = $invoice_insert_id; - $ip_invoice_items['item_product_id'] = $product_id; - $ip_invoice_items['item_date_added'] = $invoice_date; - $ip_invoice_items['item_name'] = $item_name; - $ip_invoice_items['item_description'] = $item_description; - $ip_invoice_items['item_quantity'] = $item_quantity; - $ip_invoice_items['item_price'] = $item_price; - $ip_invoice_items['item_order'] = $item_order; - $ip_invoice_items['item_product_unit'] = $item_product_unit; - $ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid; - $ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid; - $item_insert_id = $this->Zohobook_model->insert($ip_invoice_items,'ip_invoice_items'); - if($item_insert_id) - log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); - else - log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); - - //tax amount -- ip_invoice_item_amounts - table - $ip_invoice_item_amounts['item_id'] = $item_insert_id; - $ip_invoice_item_amounts['item_subtotal'] = $item_subtotal; - $ip_invoice_item_amounts['item_tax_total'] = $item_tax_total; - $ip_invoice_item_amounts['item_total'] = $item_total; - $ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt; - $ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt; - $ip_invoice_item_amounts['item_discount'] = $item_discount; - $ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt; - $result_tax_amount_insert = $this->Zohobook_model->insert($ip_invoice_item_amounts,'ip_invoice_item_amounts'); - if($result_tax_amount_insert) - log_message('error', 'Data insert success DB : ip_invoice_item_amounts '); - else - log_message('error', 'Data insert failed DB : ip_invoice_item_amounts '); - - //custom fields insert - // batch_no - $ip_invoice_custom_b['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_b['invoice_custom_fieldid'] = 62; - $ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no; - $result_invoice_custom_insert = $this->Zohobook_model->insert($ip_invoice_custom_b,'ip_invoice_custom'); - if($result_invoice_custom_insert) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // vehicle_number - $ip_invoice_custom_v['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_v['invoice_custom_fieldid'] = 8; - $ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number; - $res_vehicle = $this->Zohobook_model->insert($ip_invoice_custom_v,'ip_invoice_custom'); - if($res_vehicle) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // transport_mode - $ip_invoice_custom_t['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_t['invoice_custom_fieldid'] = 7; - $ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode; - $res_transport_mode = $this->Zohobook_model->insert($ip_invoice_custom_t,'ip_invoice_custom'); - if($res_transport_mode) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // purchase_order_date - $ip_invoice_custom_p['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_p['invoice_custom_fieldid'] = 15; - $ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date; - $res_purchase_order_date =$this->Zohobook_model->insert($ip_invoice_custom_p,'ip_invoice_custom'); - if($res_purchase_order_date) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // driver - $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_d['invoice_custom_fieldid'] = 58; - $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver; - $res_driver = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); - if($res_driver) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // place_of_supply - $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_d['invoice_custom_fieldid'] = 10; - $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply; - $res_place = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); - if($res_place) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - $insert_count = $insert_count + 1; - } - else // update invoice status, especially for cancelled invoices - { - if($status == "void") - { - $sql_invoice_update['invoice_status_id'] = 5; - $sql_invoice_update = $this->Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices'); - if($sql_invoice_update) - { - log_message('error', 'Data update success DB : ip_invoices '); - } - else - { - log_message('error', 'Data update failed DB : ip_invoices '); - } - $update_count = $update_count + 1; - } - } - } - echo 'new invoice inserted count- '. $insert_count . '/'.'cancelled status updated count - ' . $update_count; - - // curl_close($ch); - } - } - catch (Exception $e) { - $data['err'] = $e->getMessage(); - $data['last_query'] = $this->db->last_query(); - $this->Zohobook_model->insert($data,'zohobook_api_err'); - log_message('ERROR', "Data insertion failed : " . $e->getMessage()); - - } - } - //end - // END zoho API - - - -} - -?> +load->model('login_model'); + $this->load->model('Zohobook_api_model','Zohobook_model'); + $this->load->helper('zohobooks_fetch_api_helper'); + } + + /** + * Index Page for this controller. + */ + public function index() + { + $this->isLoggedIn(); + } + + /** + * This function used to check the user is logged in or not + */ + function isLoggedIn() + { + $isLoggedIn = $this->session->userdata('isLoggedIn'); + + if(!isset($isLoggedIn) || $isLoggedIn != TRUE) + { + // print_r($this->session->all_userdata()); + $this->load->view('login'); + + } + else + { + redirect('/dashboard'); + } + } + + + /** + * This function used to logged in user + */ + public function loginMe() + { + $this->load->library('form_validation'); + + // $this->form_validation->set_rules('email', 'Email', 'required|valid_email|max_length[128]|xss_clean|trim'); + $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|'); + $designation=''; + $role=''; + + if($this->form_validation->run() == FALSE) + { + $this->index(); + } + else + { + $email = $this->input->post('email'); + $password = $this->input->post('password'); + + $result = $this->login_model->loginMe($email, $password); + + if(count($result) > 0) + { + + // $det= $this->login_model->Accessdep($res->EmpID); + // print_r($det); + // die(); + + foreach ($result as $res) + { + log_message('ERROR','#####loggin_name : ' . $res->FirstName); + $sessionArray = array('userId'=>$res->userId, + 'role'=>$res->roleId, + 'roleText'=>$res->role, + 'name'=>$res->FirstName, + //'Designation'=>$res->Designation, + 'DEPCode'=>$res->DEPCode, + 'HeadDept'=>$res->HeadDept, + 'depaccess'=>$this->login_model->Accessdep($res->EmpID), + 'DepartmentName'=>$res->DepartmentName, + 'EmpID' => $res->EmpID, + 'isLoggedIn' => TRUE + ); + + $this->session->set_userdata($sessionArray); + + //$role=$res->roleId; + //$designation=$res->Designation; + $DEPCode=$res->DEPCode; + + + + } + if ($DEPCode == SECURITY) + { + redirect('/Addigr'); + } + else + { + redirect('/dashboard'); + } + } + else + { + $this->session->set_flashdata('error', 'Email or password mismatch'); + redirect('login'); + + } + } + } + + /** + * This function used to load forgot password view + */ + function forgotPassword() + { + $this->load->view('forgotPassword'); + } + + + /** + * To reset password of the user (without one time code) + */ + function resetPasswordUser(){ + // echo 'hi'; + // die(); + + $mobileno = $this->input->post('phno'); + $emailid = $this->input->post('email'); + $result = $this->login_model->getuserid($mobileno,$emailid); + + if(!empty($result)){ + + $string = "abcd".rand(100000,999999)."lmnxyz"; + $string_shuffled = str_shuffle($string); + $passcode = substr($string_shuffled, 1, 6); + $password = "SIDH@".$passcode; + + $mobile = "91".$result[0]->ContactNumber; + //$msg = "Your Password is 'resico1234' sent from Resico Industries "; + $msg = "Hi " .$result[0]->FirstName. ", + \n Your password has been resetted sucessfully. + \n Please login with your new password '".$password."'"; + + $message = urlencode($msg); + + $ch=curl_init(); + curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $output =curl_exec($ch); + curl_close($ch); + + $resetpassword = getHashedPassword($password); + + $updatepassword = $this->login_model->updatepassword($result[0]->userId,$resetpassword); + + echo ""; + redirect('/loginMe','refresh'); + } + else{ + echo ""; + redirect('/loginMe','refresh'); + } + } + + + /** + * To Get One time code to reset password of the user (ajax call) + */ + /** function getOTP() + * { + * $id = $this->input->post('id'); + * $result = $this->login_model->temp($id); + * if(!empty($result)){ + * $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + * $string_shuffled = str_shuffle($string); + * $password = substr($string_shuffled, 1, 7); + * $otp = rand(1000, 9999); + * echo "resico@".rand(1000,9999);die; + * + * //print_r($result);die; + * //$result[0]->ContactNumber; + * + * $mobile = "91".$result[0]->ContactNumber; + * //$msg = "Your Password is 'resico1234' sent from Resico Industries "; + * $msg = "Hi " .$result[0]->FirstName. ", + * \n We have generated One Time Code For You. This code used for reset your password + * \n YOUR CODE IS'".$password."'and'".$otp."'"; + * + * $message = urlencode($msg); + * // echo $mobile , $message; + * $ch=curl_init(); + * curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH"); + * curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + * $output =curl_exec($ch); + * + * //return $output; + * //print_r($output);exit(); + * curl_close($ch); + * //echo json_encode($result); + * $updateotp = $this->login_model->temp2($result[0]->userId,$otp); + * $data = $updateotp[0]->OTP; + * echo $data; + * }} + */ + + /** + * After Getting One time code + * Reset password of the user (with OTP) + */ + /** function resetPasswordConfirmUser(){ + * + * // $this->load->library('form_validation'); + * + * // $this->form_validation->set_rules('newPassword','New password','required|max_length[20]'); + * // $this->form_validation->set_rules('confirmPassword','Confirm new password','required|matches[newPassword]|max_length[20]'); + * + * $newPassword = $this->input->post('newPassword'); + * $ConfirmPassword = $this->input->post('confirmPassword'); + * + * $mobileno = $this->input->post('phno'); + * + * $da ta = $this->login_model->getuserdtl($mobileno); + * $userid = $data[0]->userId; + * $OTP = NULL; + * + * $Array = array('password'=>getHashedPassword($newPassword),'OTP'=>$OTP); + * + * $result = $this->login_model->resetpassword($Array,$userid); + * + * if($result > 0) + * { + * echo ""; redirect('login','refresh'); + * } + * else + * { + * echo ""; redirect('login','refresh'); + * } + * + * } + */ + + // start zoho API + + function zohobooks_api_fetch_all(){ +// print_r($_GET); +// echo isset($_GET['from']) ? $_GET['from'] : 'n'; +// echo isset($_GET['to']) ? $_GET['to'] : 'n'; + // die(); + try{ + // if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null) + // { + // $ch=curl_init(); + $this->load->helper('zohobooks_fetch_api_helper'); + if(isset($_GET['from']) && $_GET['from'] != null && isset($_GET['to']) && $_GET['to'] != null) + { + $date_today = $_GET['to']; + $date_yesterday = $_GET['from']; + } + else + { + $date_today = date('Y-m-d'); + $date_yesterday = date('Y-m-d',strtotime('-3 day',strtotime($date_today))); + } + // echo $date_today.'--'.$date_yesterday; + $chk_acc_token_val = $this->Zohobook_model->get_data('zohobook_accesstoken','id' , 1); + // print_r($chk_acc_token_val);//die(); + $date = new DateTime($chk_acc_token_val[0]['created_at']); + //print_r($date); + $date->add(new DateInterval('PT1H')); + //print_r($date); + //echo '****************'; + //print_r(date('Y-m-d h:i:s')); + $token = 0; + if ($date->format('Y-m-d H:i:s') > date('Y-m-d H:i:s')) { $token = $chk_acc_token_val[0]['token']; } + else { $token = generateNewToken(); $tokendata['token'] = $token; $this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken'); } + // $token = generateNewToken(); $tokendata['token'] = $token; + //$this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken'); + $result = getheringInvoiceDetails($date_today , $date_yesterday , $token); + // echo json_encode($result);die(); + $headers_new = $result['headers_new']; + $res = json_decode($result['data'],true); + $inv_array = $res['invoices']; + // echo json_encode($inv_array);die(); + foreach($inv_array as $inv){ + $invoice_id = $inv['invoice_id']; + //filter only einvoice status pushed invoices only + //&& isset($inv['einvoice_details']) && isset($inv['einvoice_details']['status']) && ($inv['einvoice_details']['status'] == 'pushed') + if($invoice_id !== "" ){ + $organization_id = '655654572'; + $result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new); + $resall = json_decode($result2,true); + $res2[] = $resall['invoice']; + } + } + $insert_count = 0; + $update_count = 0; + // echo json_encode($res2);die(); + foreach($res2 as $rs) + { + $gst_no = $rs['gst_no']; + $invoice_number = $rs['invoice_number']; + $invoice_date = $rs['date']; + $status = $rs['status']; + $due_date = $rs['due_date']; + + $invoice_time=$rs['created_time']; + $time_array = explode("T", $invoice_time); + $time_array = explode("+",$time_array[1]); + $invoice_time = $time_array[0]; + + $sql_invoice_chk = $this->Zohobook_model->ip_invoices($invoice_number , $invoice_date); + if($sql_invoice_chk <= 0) + { + + $gst_sql = $this->Zohobook_model->ip_clients($gst_no); + if($gst_sql) + { + $client_id = $gst_sql[0]['client_id']; + log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no); + $gst_no_data['client_tax_code'] = $gst_no; + $gst_sql = $this->Zohobook_model->insert($gst_no_data,'ip_clients'); + $client_id = $gst_sql[0]['tax_rate_id']; + log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id); + } + + + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } + $url_key = $randomString; + + $ip_invoices['user_id'] = 1; + $ip_invoices['client_id'] = $client_id; + $ip_invoices['invoice_group_id'] = 6; + $ip_invoices['invoice_status_id'] = ($status == 'draft' ? 1 : (($status == 'sent' || $status == 'overdue') ? 2 : 5)); + $ip_invoices['invoice_date_created'] = $invoice_date; + $ip_invoices['invoice_time_created'] = $invoice_time; + $ip_invoices['invoice_date_due'] = $due_date; + $ip_invoices['invoice_number'] = $invoice_number; + $ip_invoices['invoice_url_key'] = $url_key; + $ip_invoices['receivedstatus'] = 'ST066'; + $ip_invoices['credit_status'] = 0; + $invoice_insert_id = $this->Zohobook_model->insert($ip_invoices,'ip_invoices'); + if($invoice_insert_id) + { + log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id); + $insert_count = $insert_count + 1; + //start invoice level custom fields + + //custom fields insert + + $batch_no = isset($rs['custom_fields'][5]['value']) ? $rs['custom_fields'][5]['value'] : ""; + // $batch_no = ""; + $vehicle_number = $rs['custom_field_hash']['cf_vehicle_number']; + $transport_mode =$rs['custom_field_hash']['cf_transport_mode']; + $purchase_order_date = $rs['custom_field_hash']['cf_purchase_order_date']; + $driver = $rs['custom_field_hash']['cf_driver']; + $place_of_supply = $rs['custom_field_hash']['cf_place_of_supply']; + // batch_no + $ip_invoice_custom_b['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_b['invoice_custom_fieldid'] = 62; + $ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no; + $result_invoice_custom_insert = $this->Zohobook_model->insert($ip_invoice_custom_b,'ip_invoice_custom'); + if($result_invoice_custom_insert) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // vehicle_number + $ip_invoice_custom_v['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_v['invoice_custom_fieldid'] = 8; + $ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number; + $res_vehicle = $this->Zohobook_model->insert($ip_invoice_custom_v,'ip_invoice_custom'); + if($res_vehicle) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // transport_mode + $ip_invoice_custom_t['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_t['invoice_custom_fieldid'] = 7; + $ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode; + $res_transport_mode = $this->Zohobook_model->insert($ip_invoice_custom_t,'ip_invoice_custom'); + if($res_transport_mode) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // purchase_order_date + $ip_invoice_custom_p['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_p['invoice_custom_fieldid'] = 15; + $ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date; + $res_purchase_order_date =$this->Zohobook_model->insert($ip_invoice_custom_p,'ip_invoice_custom'); + if($res_purchase_order_date) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // driver + $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_d['invoice_custom_fieldid'] = 58; + $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver; + $res_driver = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); + if($res_driver) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // place_of_supply + $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_d['invoice_custom_fieldid'] = 10; + $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply; + $res_place = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); + if($res_place) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + //end invoice level custom fields + + //if line items available + if(isset($rs['line_items']) && count($rs['line_items']) > 0) + { + log_message('error', 'Processing line items'.count($rs['line_items'])); + + for($i = 0; $i< count($rs['line_items']);$i++) + { //start insert line items + $sku = $rs['line_items'][$i]['sku']; + + + $item_price = $rs['line_items'][$i]['rate']; + $item_order = $rs['line_items'][$i]['item_order']; + $item_product_unit = $rs['line_items'][$i]['unit']; + $item_name = $rs['line_items'][$i]['name']; + $item_description = $rs['line_items'][$i]['description']; + $item_quantity = $rs['line_items'][$i]['quantity']; + $cgst = $rs['line_items'][$i]['line_item_taxes'][1]['tax_name']; + $sgst = $rs['line_items'][$i]['line_item_taxes'][0]['tax_name']; + $cgst = $cgst[4]; + $sgst = $sgst[4]; + $cgst = $cgst.'.000'; + $getcgsttax = $this->Zohobook_model->ip_tax_rates($cgst); + if($getcgsttax) + { + $cgsttaxid = $getcgsttax[0]['tax_rate_id']; + log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst); + $cgst_data['tax_rate_percent'] = $cgst; + $getcgsttax = $this->Zohobook_model->insert($cgst_data,'ip_tax_rates'); + $cgsttaxid = $getcgsttax[0]['tax_rate_id']; + log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid); + } + + $sgst = $sgst.'.000'; + $getsgsttax = $this->Zohobook_model->ip_tax_rates($sgst); + if($getsgsttax) + { + $sgsttaxid = $getsgsttax[0]['tax_rate_id']; + log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst); + $sgst_data['tax_rate_percent'] = $sgst; + $getsgsttax = $this->Zohobook_model->insert($sgst_data,'ip_tax_rates'); + $sgsttaxid = $getsgsttax[0]['tax_rate_id']; + log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid); + } + + $item_subtotal = $rs['line_items'][$i]['item_total']; + + + $item_sgst_amt = $rs['line_items'][$i]['line_item_taxes'][0]['tax_amount']; + $item_cgst_amt = $rs['line_items'][$i]['line_item_taxes'][1]['tax_amount']; + $item_tax_total = ($item_sgst_amt + $item_cgst_amt); + $item_total = ($item_subtotal + $item_tax_total); + + $item_discount = 0.00; + $item_igst_amt = 0.00; + // if($batch_no==""){ $batch_no = "";} + + + $sku_sql = $this->Zohobook_model->ip_products($sku); + if($sku_sql) + { + $product_id = $sku_sql[0]['product_id']; + log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku); + $sku_data['product_name'] = $item_name; + $sku_data['product_description'] = $item_description; + $sku_data['sku'] = $sku; + $sku_sql = $this->Zohobook_model->insert($sku_data,'ip_products'); + $product_id = $sku_sql[0]['sku']; + log_message('error', 'sku'.$sku); + log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id); + } + + //#1 + + $ip_invoice_items['invoice_id'] = $invoice_insert_id; + $ip_invoice_items['item_product_id'] = $product_id; + $ip_invoice_items['item_date_added'] = $invoice_date; + $ip_invoice_items['item_name'] = $item_name; + $ip_invoice_items['item_description'] = $item_description; + $ip_invoice_items['item_quantity'] = $item_quantity; + $ip_invoice_items['item_price'] = $item_price; + $ip_invoice_items['item_order'] = $item_order; + $ip_invoice_items['item_product_unit'] = $item_product_unit; + $ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid; + $ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid; + $item_insert_id = $this->Zohobook_model->insert($ip_invoice_items,'ip_invoice_items'); + if($item_insert_id) + log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); + else + log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); + + //tax amount -- ip_invoice_item_amounts - table + $ip_invoice_item_amounts['item_id'] = $item_insert_id; + $ip_invoice_item_amounts['item_subtotal'] = $item_subtotal; + $ip_invoice_item_amounts['item_tax_total'] = $item_tax_total; + $ip_invoice_item_amounts['item_total'] = $item_total; + $ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt; + $ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt; + $ip_invoice_item_amounts['item_discount'] = $item_discount; + $ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt; + $result_tax_amount_insert = $this->Zohobook_model->insert($ip_invoice_item_amounts,'ip_invoice_item_amounts'); + if($result_tax_amount_insert) + log_message('error', 'Data insert success DB : ip_invoice_item_amounts '); + else + log_message('error', 'Data insert failed DB : ip_invoice_item_amounts '); + + } //end line items insert + + } + else + { + log_message('error', 'Line Items not found in API result'); + } + } + else + { + log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id); + } + + + } + else // update invoice status, especially for cancelled invoices + { + if($status == "void" || $status == "sent" || $status == "ovedue") + { + $sql_invoice_update = array(); + $sql_invoice_update['invoice_status_id'] = (($status == "sent" || $status == "ovedue") ? 2 : 5); + // echo 'script' . $invoice_number. $status; + // print_r( $sql_invoice_update); + // echo '
'; + $sql_invoice_update = $this->Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices'); + if($sql_invoice_update) + { + log_message('error', 'Data update success DB : ip_invoices '); + } + else + { + log_message('error', 'Data update failed DB : ip_invoices '); + } + $update_count = $update_count + 1; + } + } + } + echo 'new invoice inserted count- '. $insert_count . '/'.'status updated count - ' . $update_count; + + // curl_close($ch); + // } + } + catch (Exception $e) { + $data['err'] = $e->getMessage(); + $data['last_query'] = $this->db->last_query(); + $this->Zohobook_model->insert($data,'zohobook_api_err'); + log_message('ERROR', "Data insertion failed : " . $e->getMessage()); + + } + } + //end + // END zoho API + + function check_existing_invoice_with_item($arrToCheck,$arrOfInvoices) + { + + } + +} + +?> diff --git a/application/controllers/payslip.php b/application/controllers/payslip.php index 865b5db6..434cea5b 100644 --- a/application/controllers/payslip.php +++ b/application/controllers/payslip.php @@ -984,9 +984,12 @@ function phpAlert($msg) { } $Estimate_first = explode(".",$Estimate); - if(!is_numeric($Estimate) || (strlen((string)$Estimate))>8 || (strlen((string)$Estimate_first[0]))> 5) + if(!is_numeric($Estimate) || (strlen((string)$Estimate))>8 || (strlen((string)$Estimate_first[0]))> 7) { - //echo $EmpID . "-Loan Recoverd Invalid Data!"; + // echo $Estimate; + // print_r($Estimate_first); + + // echo $EmpID . "-Loan Recoverd Invalid Data!"; $ErrorFlag++; } @@ -1008,6 +1011,9 @@ function phpAlert($msg) { } + // echo $TotalErrorFlag; + // echo $ErrorEmpId; + // die(); if($TotalErrorFlag == 0) { diff --git a/application/controllers/quality.php b/application/controllers/quality.php index 0c2348bf..9d7fc7f6 100644 --- a/application/controllers/quality.php +++ b/application/controllers/quality.php @@ -1,842 +1,842 @@ -load->model('quality_model'); - $this->load->library('form_validation'); - $this->load->model('Zohobook_api_model','Zohobook_model'); - $this->load->helper('zohobooks_fetch_api_helper'); - //$this->load->library('dompdf_gen'); - $this->isLoggedIn(); - } - /** - * This function used to load the first screen of the user - */ - public function index() - { - $data['products'] = $this->quality_model->getAllprodcuts(); - $data['customers'] = $this->quality_model->getAllcustomers(); - $data['existspec'] = $this->quality_model->getAllspec(); - $data['existspecinward'] = $this->quality_model->getAllspecInward(); - $this->global['pageTitle'] = 'Siddharth : Quality Master'; - - $this->loadViews("qualitymasterlistview", $this->global, $data , NULL); - } - - - public function reportList() - { - $data['records'] = $this->quality_model->getTestMasterforList(); - - $this->global['pageTitle'] = 'Siddharth : Prodcut Report List '; - $this->loadViews("reportmasterlist", $this->global, $data , NULL); - } - - public function reportListInward() - { - $data['records'] = $this->quality_model->getTestMasterforListInward(); - - $this->global['pageTitle'] = 'Siddharth : Report List Inward'; - $this->loadViews("reportmasterlist_inward", $this->global, $data , NULL); - } - - - - function addNewPage() - { - $data['productsoutward'] = $this->quality_model->getAllprodcuts(); - $data['customersoutward'] = $this->quality_model->getAllcustomers(); - - $data['productsinward'] = $this->quality_model->getAllprodcutsInward(); - $data['customersinward'] = $this->quality_model->getAllcustomersInward(); - - $this->global['pageTitle'] = 'Siddharth : Quality Master'; - - $this->loadViews("qualitymaster", $this->global, $data , NULL); - } - - function saveSpectficationData() - { - $product = $this->input->post('param2'); - $customer = $this->input->post('param3'); - $jsondata = $this->input->post('param1'); - $type = $this->input->post('param4'); - - - //echo $type;die(); - $createdby = $this->session->userdata ( 'userId' ); - $phpdata = json_decode($jsondata,true); - $total = 0; - // echo $product .'-'. $customer; - //print_r($phpdata);die(); - - foreach($phpdata as $data) - { - $name = $data['Name']; - $name = strtoupper($name); - $uom = $data['UOM']; - $min = $data['Min']; - $max = $data['Max']; - $temp = $data['Temp']; - $rawsandtest = $data['Raw Sand Test']; - - $res = 0; - if(strtolower($rawsandtest) == 'yes') - { - $rawsandtest = 1; - } - else - { - $rawsandtest = 0; - } - - - - $isExist = $this->quality_model->checkExist($product,$customer,$name,$type); - //echo $isExist[0]->count;die(); - if($isExist[0]->count == 0) - { - - $tostore = array('customer_id'=>$customer,'product_id'=>$product,'testtype'=>$name,'uom'=>$uom,'min'=>$min,'max'=>$max,'temp'=>$temp,'type'=>$type,'subtype' => $rawsandtest,'created_by'=>$createdby); - //print_r($tostore); - $res = $this->quality_model->addSpecMast($tostore); - //echo 'i'.$res; - } - else if($isExist[0]->count == 1) - { - - $tostore = array('uom'=>$uom,'min'=>$min,'max'=>$max,'temp'=>$temp,'type'=>$type,'subtype' => $rawsandtest,'updated_by'=>$createdby); - $res = $this->quality_model->updateSpecMast($tostore,$product,$customer,$name,$type); - //echo 'u'.$res; - } - - $total +=$res; - } - - echo $total.'- Specification Saved Successfully'; - } - - function deleteSpecification() - { - $spname = $this->input->post('param1'); - $product = $this->input->post('param2'); - $customer = $this->input->post('param3'); - $type = $this->input->post('param4'); - - $res = $this->quality_model->deleteSpecification($spname,$product,$customer,$type); - if($res == 1) - { - echo "Deleted Successfully..!"; - } - else - { - echo "Something Went Wrong..!Try later"; - } - - } - - function report() - { - - $data['records'] = $this->quality_model->getDataforReport(); - $data['emplist'] = $this->quality_model->getEmplistforReport(); - $this->global['pageTitle'] = 'Siddharth : Inspection Report Screen'; - $this->loadViews("qualityreport", $this->global, $data, NULL); - } - - function viewSpec() - { - $prodcutid = $this->uri->segment(3); - $customerid =$this->uri->segment(4); - $type =$this->uri->segment(5); - $data['specifications'] = $this->quality_model->getIndividualSpec($prodcutid,$customerid,$type); - $this->global['pageTitle'] = 'Siddharth : View reports Lists'; - - $this->loadViews("viewIndSpec", $this->global, $data, NULL); - - } - - function viewIndReport() - { - $reportid = $this->uri->segment(3); - - $data['reportdata'] = $this->quality_model->getIndividualReportData($reportid); - $this->global['pageTitle'] = 'Siddharth : View Individual Report'; - $this->loadViews("viewindreport", $this->global, $data, NULL); - - } - - function viewIndInwardReport() - { - $reportid = $this->uri->segment(3); - - $data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid); - $this->global['pageTitle'] = 'Siddharth : View Individual Report'; - $this->loadViews("viewindInwardreport", $this->global, $data, NULL); - - } - - function printReportPDF() - { - $type = ''; - $html = ''; - $filename = ''; - if($this->input->post('type')) - { - $type = $this->input->post('type'); - } - $reportid = $this->input->post('rid'); - - if($type != 'INWARD' or $type == ''){ - $data['reportdata'] = $this->quality_model->getIndividualReportData($reportid); - $filename = 'PRE DESPATCH INSPECTION REPORT'.$reportid; - $html = $this->load->View("viewindreportpdf",$data,true); - } - else if($type == 'INWARD') - { - $data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid); - $filename = 'INWARD MATERIAL INSPECTION REPORT'.$reportid; - $html = $this->load->View("viewindinwardreportpdf",$data,true); - } - // echo $html;die; - ob_end_clean(); - $mpdf=new mPDF('utf-8','A4-P',7,10,10, 10, 10, 24, 4, 6); - $mpdf->SetDisplayMode('fullpage'); - $mpdf->showImageErrors = true; - $mpdf->list_indent_first_level = 1; - $mpdf->setAutoTopMargin = 'stretch'; - $mpdf->setAutoBottomMargin = 'stretch'; - $mpdf->WriteHTML($html); - $mpdf->Output($filename.'.pdf','I'); - - } - - function getAllSpecforReport() - { - $productid = $this->input->post('param1'); - $customerid = $this->input->post('param2'); - $res = ''; - if($this->input->post('param3')) - { - $ttype = $this->input->post('param3'); - $res = $this->quality_model->getSpecifications($productid,$customerid,$ttype); - } - else - { - - $res = $this->quality_model->getSpecifications($productid,$customerid); - } - - - echo json_encode($res); - } - - - function saveTestReportData() - { - - - date_default_timezone_get('Asia/Kolkata'); - $testjson = $this->input->post('param1'); - $loijson = $this->input->post('param2'); - $afsjson = $this->input->post('param3'); - $invoiceno = $this->input->post('param4'); - $batchno = $this->input->post('param5'); - $chart = $this->input->post('param7'); - $batchno = date_format(date_create($batchno),'Y-m-d'); - - $approver = $this->input->post('param6'); - - $testphpdata = json_decode($testjson,true); - $loiphpdata = json_decode($loijson,true); - - $afsphpdata = json_decode($afsjson,true); - //print_r($afsphpdata);die(); - $createdon = date('Y-m-d H:i:s'); - $createby = $this->session->userdata ( 'userId' ); - $document = null; - if(!empty($_FILES['rfile']['name'])) - { - - - $fs = $this->uploadFile(); - $document = $fs; - - } - - $masterreportdata = array('invoiceid'=>$invoiceno,'batchdate'=>$batchno,'createdby'=>$createby,'createdon'=>$createdon,'approvedby'=>$approver,'chartdata'=>$chart,'document'=>$document); - $MASTERID = $this->quality_model->saveMasterTestData($masterreportdata); - - - - $descrition = ''; - $min = ''; - $max = ''; - $uom = ''; - $act1 = ''; - $act2 = ''; - $act3 = ''; - $average = ''; - $results = ''; - $remarks1 = ''; - foreach($testphpdata as $data) - { - //print_r($data);die(); - $descrition = $data['Description']; - $min = $data['SpecificationMin']; - $max = $data['SpecificationMax']; - $uom = $data['SpecificationUOM']; - $act1 = $data['ACT X1']; - $act2 = $data['ACT X2']; - $act3 = $data['ACT X3']; - $average = $data['Average']; - $results = $data['Results']; - $remarks1 = $data['Remarks']; - $testreportdata = array('testreport_id'=>$MASTERID,'description'=>$descrition,'min'=>$min,'max'=>$max,'UOM'=>$uom,'act1'=>$act1,'act2'=>$act2,'act3'=>$act3,'average'=>$average,'result'=>$results,'remarks'=>$remarks1); - $reportid = $this->quality_model->saveTestReportData($testreportdata); - } - - - $start = ''; - $end = ''; - $temp = ''; - $w1 = ''; - $w2 = ''; - $w3 = ''; - $loip = ''; - $remark = ''; - foreach($loiphpdata as $loi) - { - $start = $loi['Heating Timestart']; - $end = $loi['Heating Timeend']; - $temp = $loi['Temp *c']; - $w1 = $loi['Crucible Weight w1(g)']; - $w2 = $loi['Before Heatingw2(g)']; - $w3 = $loi['After Heatingw3(g)']; - $loip = $loi['L.O.I %']; - $remark = $loi['Remarks']; - //echo $loip; - //echo $remark;die(); - $loitabledata = array('testreport_id'=>$MASTERID,'start_time'=>$start,'end_time'=>$end,'temp'=>$temp,'w1'=>$w1,'w2'=>$w2,'w3'=>$w3,'loi_percentage'=>$loip,'remarks'=>$remark); - $loiid = $this->quality_model->saveTestReportLOIData($loitabledata); - - } - - $count =0; - foreach($afsphpdata as $afs) - { - $count++; - if($count != 12){ - $ssize = $afs['Sieve Size µm']; - $sandweight = $afs['Sand Weight']; - $Percentage = $afs['Percentage']; - $Multiplier = $afs['Multiplier']; - $Product = $afs['Product']; - $afstabledata = array('testreport_id'=>$MASTERID,'sieve_size'=>$ssize,'sandweight'=>$sandweight,'percentage'=>$Percentage,'multiplier'=>$Multiplier,'product'=>$Product); - $afsid = $this->quality_model->saveTestReportAFSData($afstabledata); - } - } - - echo "Report Data Saved Successfully!"; - - - } - - - function saveInwardTestReportData() - { - - - - date_default_timezone_get('Asia/Kolkata'); - $testjson = $this->input->post('param1'); - $loijson = $this->input->post('param2'); - $afsjson = $this->input->post('param3'); - - $igrno = $this->input->post('param4'); - $igrlineitemno = $this->input->post('param5'); - $chart = $this->input->post('param7'); - $report_date = $this->input->post('param8'); - $report_date = date_format(date_create($report_date),'Y-m-d'); - - $approver = $this->input->post('param6'); - - $testphpdata = json_decode($testjson,true); - $loiphpdata = json_decode($loijson,true); - - $afsphpdata = json_decode($afsjson,true); - //print_r($afsphpdata);die(); - $createdon = date('Y-m-d H:i:s'); - $createby = $this->session->userdata ( 'userId' ); - $document = null; - if(!empty($_FILES['rfile']['name'])) - { - - - $fs = $this->uploadFile(); - $document = $fs; - - } - $masterreportdata = array('igrno'=>$igrno,'igrlineitemno'=>$igrlineitemno,'batchdate'=>$report_date,'createdby'=>$createby,'createdon'=>$createdon,'approvedby'=>$approver,'chartdata'=>$chart,'document'=>$document); - //print_r($masterreportdata);die; - $MASTERID = $this->quality_model->saveMasterTestData($masterreportdata); - - - - foreach($testphpdata as $data) - { - //print_r($data);die(); - $descrition = $data['Description']; - $min = $data['SpecificationMin']; - $max = $data['SpecificationMax']; - $uom = $data['SpecificationUOM']; - $act1 = $data['ACT X1']; - $act2 = $data['ACT X2']; - $act3 = $data['ACT X3']; - $average = $data['Average']; - $results = $data['Results']; - $remarks1 = $data['Remarks']; - $testreportdata = array('testreport_id'=>$MASTERID,'description'=>$descrition,'min'=>$min,'max'=>$max,'UOM'=>$uom,'act1'=>$act1,'act2'=>$act2,'act3'=>$act3,'average'=>$average,'result'=>$results,'remarks'=>$remarks1); - $reportid = $this->quality_model->saveTestReportData($testreportdata); - } - - - // $start = ''; - // $end = ''; - // $temp = ''; - // $w1 = ''; - // $w2 = ''; - // $w3 = ''; - // $loip = ''; - // $remark = ''; - foreach($loiphpdata as $loi) - { - $start = $loi['Heating Timestart']; - $end = $loi['Heating Timeend']; - $temp = $loi['Temp *c']; - $w1 = $loi['Crucible Weight w1(g)']; - $w2 = $loi['Before Heatingw2(g)']; - $w3 = $loi['After Heatingw3(g)']; - $loip = $loi['L.O.I %']; - $remark = $loi['Remarks']; - //echo $loip; - //echo $remark;die(); - $loitabledata = array('testreport_id'=>$MASTERID,'start_time'=>$start,'end_time'=>$end,'temp'=>$temp,'w1'=>$w1,'w2'=>$w2,'w3'=>$w3,'loi_percentage'=>$loip,'remarks'=>$remark); - $loiid = $this->quality_model->saveTestReportLOIData($loitabledata); - - } - - $count =0; - foreach($afsphpdata as $afs) - { - $count++; - if($count != 12){ - $ssize = $afs['Sieve Size µm']; - $mesh_size = $afs['Mesh Size']; - $sandweight = $afs['Sand Weight']; - $Percentage = $afs['Percentage']; - $Multiplier = $afs['Multiplier']; - $Product = $afs['Product']; - $afstabledata = array('testreport_id'=>$MASTERID,'sieve_size'=>$ssize,'mesh_size'=>$mesh_size,'sandweight'=>$sandweight,'percentage'=>$Percentage,'multiplier'=>$Multiplier,'product'=>$Product); - $afsid = $this->quality_model->saveTestReportAFSData($afstabledata); - } - } - - echo "Report Data Saved Successfully!"; - - - } - - - function addNewInward_Report() - { - $data['records'] = $this->quality_model->getIGRNOforReport(); - $data['reports'] = $this->quality_model->getIGRNOReport(); ; - $data['emplist'] = $this->quality_model->getEmplistforReport(); - $this->global['pageTitle'] = 'Siddharth : Inward Inspection'; - $this->loadViews("inward_report_create", $this->global,$data,NULL); - - } - - - function getIGRLineItemNo() - { - $igrno = $this->input->post('param1'); - $data['igrdetails'] = $this->quality_model->getIGRLineItemNo($igrno); - //print_r($data['igrdetails']); - echo json_encode($data['igrdetails']); - - } - - - function getIGRDetails() - { - $igrno = $this->input->post('param1'); - $igrlineitemno = $this->input->post('param2'); - $data['igrdetails'] = $this->quality_model->getIGRDataforReport($igrno,$igrlineitemno); - //print_r($data['igrdetails']); - echo json_encode($data['igrdetails']); - } - - function pageNotFound() - { - $this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found'; - - $this->loadViews("404", $this->global, NULL, NULL); - } - - function uploadFile() - { - - $pathinfo = pathinfo($_FILES['rfile']['name']); - $config['upload_path'] = 'uploads/QAD/'; - $config['allowed_types'] = '*'; - $filename = $_FILES['rfile']['name']; - $ext = end(explode('.',$filename)); - - $ext = strtolower($ext); - $fn = 'qad' . date('Y-m-d') . time() . '.' . $ext; - //print_r($fn);die(); - $config['file_name'] = $fn; - //echo $config['file_name']; - $this->load->library('upload',$config); - $this->upload->initialize($config); - - - if($this->upload->do_upload('rfile')) - { - $uploadData = $this->upload->data(); - $uploadfilename = $uploadData['file_name']; - return $uploadfilename; - - } - else - { - $error = array('error' => $this->upload->display_errors()); - $uploadfilename = ''; - print_r($error); - return null; - } - - } - - - - // start zoho API - - function zohobooks_api_fetch_all(){ - try{ - if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null) - { - // $ch=curl_init(); - $this->load->helper('zohobooks_fetch_api_helper'); - if($_GET['from'] != null && $_GET['to'] != null) - { - $date_today = $_GET['to']; - $date_yesterday = $_GET['from']; - } - else - { - $date_today = date('Y-m-d'); - $date_yesterday = date('Y-m-d',strtotime('-1 day',strtotime($date_today))); - } - $chk_acc_token_val = $this->Zohobook_model->get_data('zohobook_accesstoken','id' , 1); - $date = new DateTime($chk_acc_token_val[0]['created_at']); $date->add(new DateInterval('PT1H')); - $token = 0; - if ($date->format('Y-m-d h:i:s') > date('Y-m-d h:i:s')) { $token = $chk_acc_token_val[0]['token']; } - else { $token = generateNewToken(); $tokendata['token'] = $token; $this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken'); } - $result = getheringInvoiceDetails($date_today , $date_yesterday , $token); - // echo json_encode($result); - $headers_new = $result['headers_new']; - $res = json_decode($result['data'],true); - $inv_array = $res['invoices']; - foreach($inv_array as $inv){ - $invoice_id = $inv['invoice_id']; - if($invoice_id!==""){ - $organization_id = '655654572'; - $result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new); - $resall = json_decode($result2,true); - $res2[] = $resall['invoice']; - } - } - $insert_count = 0; - $update_count = 0; - foreach($res2 as $rs) - { - $gst_no = $rs['gst_no']; - $sku = $rs['line_items'][0]['sku']; - $invoice_number = $rs['invoice_number']; - $invoice_date = $rs['date']; - - $sql_invoice_chk = $this->Zohobook_model->ip_invoices($invoice_number , $invoice_date); - if($sql_invoice_chk <= 0) - { - $gst_no = $rs['gst_no']; - $sku = $rs['line_items'][0]['sku']; - $invoice_number = $rs['invoice_number']; - $invoice_date = $rs['date']; - $due_date = $rs['due_date']; - $item_price = $rs['line_items'][0]['rate']; - $item_order = $rs['line_items'][0]['item_order']; - $item_product_unit = $rs['line_items'][0]['unit']; - $item_name = $rs['line_items'][0]['name']; - $item_description = $rs['line_items'][0]['description']; - $item_quantity = $rs['line_items'][0]['quantity']; - // $batch_no = $rs['custom_fields'][5]['value']; - $batch_no = ""; - $invoice_time=$rs['created_time']; - $time_array = explode("T", $invoice_time); - $time_array = explode("+",$time_array[1]); - $invoice_time = $time_array[0]; - $status = $rs['status']; - - $vehicle_number = $rs['custom_field_hash']['cf_vehicle_number']; - $transport_mode =$rs['custom_field_hash']['cf_transport_mode']; - $purchase_order_date = $rs['custom_field_hash']['cf_purchase_order_date']; - $driver = $rs['custom_field_hash']['cf_driver']; - $place_of_supply = $rs['custom_field_hash']['cf_place_of_supply']; - - $cgst = $rs['taxes'][0]['tax_name']; - $sgst = $rs['taxes'][1]['tax_name']; - $cgst = $cgst[4]; - $sgst = $sgst[4]; - $cgst = $cgst.'.000'; - $getcgsttax = $this->Zohobook_model->ip_tax_rates($cgst); - if($getcgsttax) - { - $cgsttaxid = $getcgsttax[0]['tax_rate_id']; - log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst); - $cgst_data['tax_rate_percent'] = $cgst; - $getcgsttax = $this->Zohobook_model->insert($cgst_data,'ip_tax_rates'); - $cgsttaxid = $getcgsttax[0]['tax_rate_id']; - log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid); - } - - $sgst = $sgst.'.000'; - $getsgsttax = $this->Zohobook_model->ip_tax_rates($sgst); - if($getsgsttax) - { - $sgsttaxid = $getsgsttax[0]['tax_rate_id']; - log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst); - $sgst_data['tax_rate_percent'] = $sgst; - $getsgsttax = $this->Zohobook_model->insert($sgst_data,'ip_tax_rates'); - $sgsttaxid = $getsgsttax[0]['tax_rate_id']; - log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid); - } - - $item_subtotal = $rs['line_items'][0]['item_total']; - $item_tax_total = $rs['tax_total']; - $item_total = $rs['total']; - $item_sgst_amt = $rs['taxes'][1]['tax_amount']; - $item_cgst_amt = $rs['taxes'][0]['tax_amount']; - - $item_discount = 0.00; - $item_igst_amt = 0.00; - if($batch_no==""){ $batch_no = "";} - $gst_sql = $this->Zohobook_model->ip_clients($gst_no); - if($gst_sql) - { - $client_id = $gst_sql[0]['client_id']; - log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no); - $gst_no_data['client_tax_code'] = $gst_no; - $gst_sql = $this->Zohobook_model->insert($gst_no_data,'ip_clients'); - $client_id = $gst_sql[0]['tax_rate_id']; - log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id); - } - - $sku_sql = $this->Zohobook_model->ip_products($sku); - if($sku_sql) - { - $product_id = $sku_sql[0]['product_id']; - log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id); - } - else - { - log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku); - $sku_data['product_name'] = $item_name; - $sku_data['product_description'] = $item_description; - $sku_data['sku'] = $sku; - $sku_sql = $this->Zohobook_model->insert($sku_data,'ip_products'); - $product_id = $sku_sql[0]['sku']; - log_message('error', 'sku'.$sku); - log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id); - } - - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } - $url_key = $randomString; - - $ip_invoices['user_id'] = 1; - $ip_invoices['client_id'] = $client_id; - $ip_invoices['invoice_group_id'] = 6; - $ip_invoices['invoice_status_id'] = 2; - $ip_invoices['invoice_date_created'] = $invoice_date; - $ip_invoices['invoice_time_created'] = $invoice_time; - $ip_invoices['invoice_date_due'] = $due_date; - $ip_invoices['invoice_number'] = $invoice_number; - $ip_invoices['invoice_url_key'] = $url_key; - $ip_invoices['receivedstatus'] = 'ST066'; - $ip_invoices['credit_status'] = 0; - $invoice_insert_id = $this->Zohobook_model->insert($ip_invoices,'ip_invoices'); - if($invoice_insert_id) - log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id); - else - log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id); - - $ip_invoice_items['invoice_id'] = $invoice_insert_id; - $ip_invoice_items['item_product_id'] = $product_id; - $ip_invoice_items['item_date_added'] = $invoice_date; - $ip_invoice_items['item_name'] = $item_name; - $ip_invoice_items['item_description'] = $item_description; - $ip_invoice_items['item_quantity'] = $item_quantity; - $ip_invoice_items['item_price'] = $item_price; - $ip_invoice_items['item_order'] = $item_order; - $ip_invoice_items['item_product_unit'] = $item_product_unit; - $ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid; - $ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid; - $item_insert_id = $this->Zohobook_model->insert($ip_invoice_items,'ip_invoice_items'); - if($item_insert_id) - log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); - else - log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); - - //tax amount -- ip_invoice_item_amounts - table - $ip_invoice_item_amounts['item_id'] = $item_insert_id; - $ip_invoice_item_amounts['item_subtotal'] = $item_subtotal; - $ip_invoice_item_amounts['item_tax_total'] = $item_tax_total; - $ip_invoice_item_amounts['item_total'] = $item_total; - $ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt; - $ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt; - $ip_invoice_item_amounts['item_discount'] = $item_discount; - $ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt; - $result_tax_amount_insert = $this->Zohobook_model->insert($ip_invoice_item_amounts,'ip_invoice_item_amounts'); - if($result_tax_amount_insert) - log_message('error', 'Data insert success DB : ip_invoice_item_amounts '); - else - log_message('error', 'Data insert failed DB : ip_invoice_item_amounts '); - - //custom fields insert - // batch_no - $ip_invoice_custom_b['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_b['invoice_custom_fieldid'] = 62; - $ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no; - $result_invoice_custom_insert = $this->Zohobook_model->insert($ip_invoice_custom_b,'ip_invoice_custom'); - if($result_invoice_custom_insert) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // vehicle_number - $ip_invoice_custom_v['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_v['invoice_custom_fieldid'] = 8; - $ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number; - $res_vehicle = $this->Zohobook_model->insert($ip_invoice_custom_v,'ip_invoice_custom'); - if($res_vehicle) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // transport_mode - $ip_invoice_custom_t['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_t['invoice_custom_fieldid'] = 7; - $ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode; - $res_transport_mode = $this->Zohobook_model->insert($ip_invoice_custom_t,'ip_invoice_custom'); - if($res_transport_mode) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // purchase_order_date - $ip_invoice_custom_p['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_p['invoice_custom_fieldid'] = 15; - $ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date; - $res_purchase_order_date =$this->Zohobook_model->insert($ip_invoice_custom_p,'ip_invoice_custom'); - if($res_purchase_order_date) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // driver - $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_d['invoice_custom_fieldid'] = 58; - $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver; - $res_driver = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); - if($res_driver) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - // place_of_supply - $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; - $ip_invoice_custom_d['invoice_custom_fieldid'] = 10; - $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply; - $res_place = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); - if($res_place) - log_message('error', 'Data insert success DB : ip_invoice_custom '); - else - log_message('error', 'Data insert failed DB : ip_invoice_custom '); - $insert_count = $insert_count + 1; - } - else // update invoice status, especially for cancelled invoices - { - if($status == "void") - { - $sql_invoice_update['invoice_status_id'] = 5; - $sql_invoice_update = $this->Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices'); - if($sql_invoice_update) - { - log_message('error', 'Data update success DB : ip_invoices '); - } - else - { - log_message('error', 'Data update failed DB : ip_invoices '); - } - $update_count = $update_count + 1; - } - } - } - echo 'new invoice inserted count- '. $insert_count . '/'.'cancelled status updated count - ' . $update_count; - - // curl_close($ch); - } - } - catch (Exception $e) { - $data['err'] = $e->getMessage(); - $data['last_query'] = $this->db->last_query(); - $this->Zohobook_model->insert($data,'zohobook_api_err'); - log_message('ERROR', "Data insertion failed : " . $e->getMessage()); - - } - } - //end - // END zoho API - - - -} +load->model('quality_model'); + $this->load->library('form_validation'); + $this->load->model('Zohobook_api_model','Zohobook_model'); + $this->load->helper('zohobooks_fetch_api_helper'); + //$this->load->library('dompdf_gen'); + $this->isLoggedIn(); + } + /** + * This function used to load the first screen of the user + */ + public function index() + { + $data['products'] = $this->quality_model->getAllprodcuts(); + $data['customers'] = $this->quality_model->getAllcustomers(); + $data['existspec'] = $this->quality_model->getAllspec(); + $data['existspecinward'] = $this->quality_model->getAllspecInward(); + $this->global['pageTitle'] = 'Siddharth : Quality Master'; + + $this->loadViews("qualitymasterlistview", $this->global, $data , NULL); + } + + + public function reportList() + { + $data['records'] = $this->quality_model->getTestMasterforList(); + + $this->global['pageTitle'] = 'Siddharth : Prodcut Report List '; + $this->loadViews("reportmasterlist", $this->global, $data , NULL); + } + + public function reportListInward() + { + $data['records'] = $this->quality_model->getTestMasterforListInward(); + + $this->global['pageTitle'] = 'Siddharth : Report List Inward'; + $this->loadViews("reportmasterlist_inward", $this->global, $data , NULL); + } + + + + function addNewPage() + { + $data['productsoutward'] = $this->quality_model->getAllprodcuts(); + $data['customersoutward'] = $this->quality_model->getAllcustomers(); + + $data['productsinward'] = $this->quality_model->getAllprodcutsInward(); + $data['customersinward'] = $this->quality_model->getAllcustomersInward(); + + $this->global['pageTitle'] = 'Siddharth : Quality Master'; + + $this->loadViews("qualitymaster", $this->global, $data , NULL); + } + + function saveSpectficationData() + { + $product = $this->input->post('param2'); + $customer = $this->input->post('param3'); + $jsondata = $this->input->post('param1'); + $type = $this->input->post('param4'); + + + //echo $type;die(); + $createdby = $this->session->userdata ( 'userId' ); + $phpdata = json_decode($jsondata,true); + $total = 0; + // echo $product .'-'. $customer; + //print_r($phpdata);die(); + + foreach($phpdata as $data) + { + $name = $data['Name']; + $name = strtoupper($name); + $uom = $data['UOM']; + $min = $data['Min']; + $max = $data['Max']; + $temp = $data['Temp']; + $rawsandtest = $data['Raw Sand Test']; + + $res = 0; + if(strtolower($rawsandtest) == 'yes') + { + $rawsandtest = 1; + } + else + { + $rawsandtest = 0; + } + + + + $isExist = $this->quality_model->checkExist($product,$customer,$name,$type); + //echo $isExist[0]->count;die(); + if($isExist[0]->count == 0) + { + + $tostore = array('customer_id'=>$customer,'product_id'=>$product,'testtype'=>$name,'uom'=>$uom,'min'=>$min,'max'=>$max,'temp'=>$temp,'type'=>$type,'subtype' => $rawsandtest,'created_by'=>$createdby); + //print_r($tostore); + $res = $this->quality_model->addSpecMast($tostore); + //echo 'i'.$res; + } + else if($isExist[0]->count == 1) + { + + $tostore = array('uom'=>$uom,'min'=>$min,'max'=>$max,'temp'=>$temp,'type'=>$type,'subtype' => $rawsandtest,'updated_by'=>$createdby); + $res = $this->quality_model->updateSpecMast($tostore,$product,$customer,$name,$type); + //echo 'u'.$res; + } + + $total +=$res; + } + + echo $total.'- Specification Saved Successfully'; + } + + function deleteSpecification() + { + $spname = $this->input->post('param1'); + $product = $this->input->post('param2'); + $customer = $this->input->post('param3'); + $type = $this->input->post('param4'); + + $res = $this->quality_model->deleteSpecification($spname,$product,$customer,$type); + if($res == 1) + { + echo "Deleted Successfully..!"; + } + else + { + echo "Something Went Wrong..!Try later"; + } + + } + + function report() + { + + $data['records'] = $this->quality_model->getDataforReport(); + $data['emplist'] = $this->quality_model->getEmplistforReport(); + $this->global['pageTitle'] = 'Siddharth : Inspection Report Screen'; + $this->loadViews("qualityreport", $this->global, $data, NULL); + } + + function viewSpec() + { + $prodcutid = $this->uri->segment(3); + $customerid =$this->uri->segment(4); + $type =$this->uri->segment(5); + $data['specifications'] = $this->quality_model->getIndividualSpec($prodcutid,$customerid,$type); + $this->global['pageTitle'] = 'Siddharth : View reports Lists'; + + $this->loadViews("viewIndSpec", $this->global, $data, NULL); + + } + + function viewIndReport() + { + $reportid = $this->uri->segment(3); + + $data['reportdata'] = $this->quality_model->getIndividualReportData($reportid); + $this->global['pageTitle'] = 'Siddharth : View Individual Report'; + $this->loadViews("viewindreport", $this->global, $data, NULL); + + } + + function viewIndInwardReport() + { + $reportid = $this->uri->segment(3); + + $data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid); + $this->global['pageTitle'] = 'Siddharth : View Individual Report'; + $this->loadViews("viewindInwardreport", $this->global, $data, NULL); + + } + + function printReportPDF() + { + $type = ''; + $html = ''; + $filename = ''; + if($this->input->post('type')) + { + $type = $this->input->post('type'); + } + $reportid = $this->input->post('rid'); + + if($type != 'INWARD' or $type == ''){ + $data['reportdata'] = $this->quality_model->getIndividualReportData($reportid); + $filename = 'PRE DESPATCH INSPECTION REPORT'.$reportid; + $html = $this->load->View("viewindreportpdf",$data,true); + } + else if($type == 'INWARD') + { + $data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid); + $filename = 'INWARD MATERIAL INSPECTION REPORT'.$reportid; + $html = $this->load->View("viewindinwardreportpdf",$data,true); + } + // echo $html;die; + ob_end_clean(); + $mpdf=new mPDF('utf-8','A4-P',7,10,10, 10, 10, 24, 4, 6); + $mpdf->SetDisplayMode('fullpage'); + $mpdf->showImageErrors = true; + $mpdf->list_indent_first_level = 1; + $mpdf->setAutoTopMargin = 'stretch'; + $mpdf->setAutoBottomMargin = 'stretch'; + $mpdf->WriteHTML($html); + $mpdf->Output($filename.'.pdf','I'); + + } + + function getAllSpecforReport() + { + $productid = $this->input->post('param1'); + $customerid = $this->input->post('param2'); + $res = ''; + if($this->input->post('param3')) + { + $ttype = $this->input->post('param3'); + $res = $this->quality_model->getSpecifications($productid,$customerid,$ttype); + } + else + { + + $res = $this->quality_model->getSpecifications($productid,$customerid); + } + + + echo json_encode($res); + } + + + function saveTestReportData() + { + + + date_default_timezone_get('Asia/Kolkata'); + $testjson = $this->input->post('param1'); + $loijson = $this->input->post('param2'); + $afsjson = $this->input->post('param3'); + $invoiceno = $this->input->post('param4'); + $batchno = $this->input->post('param5'); + $chart = $this->input->post('param7'); + $batchno = date_format(date_create($batchno),'Y-m-d'); + + $approver = $this->input->post('param6'); + + $testphpdata = json_decode($testjson,true); + $loiphpdata = json_decode($loijson,true); + + $afsphpdata = json_decode($afsjson,true); + //print_r($afsphpdata);die(); + $createdon = date('Y-m-d H:i:s'); + $createby = $this->session->userdata ( 'userId' ); + $document = null; + if(!empty($_FILES['rfile']['name'])) + { + + + $fs = $this->uploadFile(); + $document = $fs; + + } + + $masterreportdata = array('invoiceid'=>$invoiceno,'batchdate'=>$batchno,'createdby'=>$createby,'createdon'=>$createdon,'approvedby'=>$approver,'chartdata'=>$chart,'document'=>$document); + $MASTERID = $this->quality_model->saveMasterTestData($masterreportdata); + + + + $descrition = ''; + $min = ''; + $max = ''; + $uom = ''; + $act1 = ''; + $act2 = ''; + $act3 = ''; + $average = ''; + $results = ''; + $remarks1 = ''; + foreach($testphpdata as $data) + { + //print_r($data);die(); + $descrition = $data['Description']; + $min = $data['SpecificationMin']; + $max = $data['SpecificationMax']; + $uom = $data['SpecificationUOM']; + $act1 = $data['ACT X1']; + $act2 = $data['ACT X2']; + $act3 = $data['ACT X3']; + $average = $data['Average']; + $results = $data['Results']; + $remarks1 = $data['Remarks']; + $testreportdata = array('testreport_id'=>$MASTERID,'description'=>$descrition,'min'=>$min,'max'=>$max,'UOM'=>$uom,'act1'=>$act1,'act2'=>$act2,'act3'=>$act3,'average'=>$average,'result'=>$results,'remarks'=>$remarks1); + $reportid = $this->quality_model->saveTestReportData($testreportdata); + } + + + $start = ''; + $end = ''; + $temp = ''; + $w1 = ''; + $w2 = ''; + $w3 = ''; + $loip = ''; + $remark = ''; + foreach($loiphpdata as $loi) + { + $start = $loi['Heating Timestart']; + $end = $loi['Heating Timeend']; + $temp = $loi['Temp *c']; + $w1 = $loi['Crucible Weight w1(g)']; + $w2 = $loi['Before Heatingw2(g)']; + $w3 = $loi['After Heatingw3(g)']; + $loip = $loi['L.O.I %']; + $remark = $loi['Remarks']; + //echo $loip; + //echo $remark;die(); + $loitabledata = array('testreport_id'=>$MASTERID,'start_time'=>$start,'end_time'=>$end,'temp'=>$temp,'w1'=>$w1,'w2'=>$w2,'w3'=>$w3,'loi_percentage'=>$loip,'remarks'=>$remark); + $loiid = $this->quality_model->saveTestReportLOIData($loitabledata); + + } + + $count =0; + foreach($afsphpdata as $afs) + { + $count++; + if($count != 12){ + $ssize = $afs['Sieve Size µm']; + $sandweight = $afs['Sand Weight']; + $Percentage = $afs['Percentage']; + $Multiplier = $afs['Multiplier']; + $Product = $afs['Product']; + $afstabledata = array('testreport_id'=>$MASTERID,'sieve_size'=>$ssize,'sandweight'=>$sandweight,'percentage'=>$Percentage,'multiplier'=>$Multiplier,'product'=>$Product); + $afsid = $this->quality_model->saveTestReportAFSData($afstabledata); + } + } + + echo "Report Data Saved Successfully!"; + + + } + + + function saveInwardTestReportData() + { + + + + date_default_timezone_get('Asia/Kolkata'); + $testjson = $this->input->post('param1'); + $loijson = $this->input->post('param2'); + $afsjson = $this->input->post('param3'); + + $igrno = $this->input->post('param4'); + $igrlineitemno = $this->input->post('param5'); + $chart = $this->input->post('param7'); + $report_date = $this->input->post('param8'); + $report_date = date_format(date_create($report_date),'Y-m-d'); + + $approver = $this->input->post('param6'); + + $testphpdata = json_decode($testjson,true); + $loiphpdata = json_decode($loijson,true); + + $afsphpdata = json_decode($afsjson,true); + //print_r($afsphpdata);die(); + $createdon = date('Y-m-d H:i:s'); + $createby = $this->session->userdata ( 'userId' ); + $document = null; + if(!empty($_FILES['rfile']['name'])) + { + + + $fs = $this->uploadFile(); + $document = $fs; + + } + $masterreportdata = array('igrno'=>$igrno,'igrlineitemno'=>$igrlineitemno,'batchdate'=>$report_date,'createdby'=>$createby,'createdon'=>$createdon,'approvedby'=>$approver,'chartdata'=>$chart,'document'=>$document); + //print_r($masterreportdata);die; + $MASTERID = $this->quality_model->saveMasterTestData($masterreportdata); + + + + foreach($testphpdata as $data) + { + //print_r($data);die(); + $descrition = $data['Description']; + $min = $data['SpecificationMin']; + $max = $data['SpecificationMax']; + $uom = $data['SpecificationUOM']; + $act1 = $data['ACT X1']; + $act2 = $data['ACT X2']; + $act3 = $data['ACT X3']; + $average = $data['Average']; + $results = $data['Results']; + $remarks1 = $data['Remarks']; + $testreportdata = array('testreport_id'=>$MASTERID,'description'=>$descrition,'min'=>$min,'max'=>$max,'UOM'=>$uom,'act1'=>$act1,'act2'=>$act2,'act3'=>$act3,'average'=>$average,'result'=>$results,'remarks'=>$remarks1); + $reportid = $this->quality_model->saveTestReportData($testreportdata); + } + + + // $start = ''; + // $end = ''; + // $temp = ''; + // $w1 = ''; + // $w2 = ''; + // $w3 = ''; + // $loip = ''; + // $remark = ''; + foreach($loiphpdata as $loi) + { + $start = $loi['Heating Timestart']; + $end = $loi['Heating Timeend']; + $temp = $loi['Temp *c']; + $w1 = $loi['Crucible Weight w1(g)']; + $w2 = $loi['Before Heatingw2(g)']; + $w3 = $loi['After Heatingw3(g)']; + $loip = $loi['L.O.I %']; + $remark = $loi['Remarks']; + //echo $loip; + //echo $remark;die(); + $loitabledata = array('testreport_id'=>$MASTERID,'start_time'=>$start,'end_time'=>$end,'temp'=>$temp,'w1'=>$w1,'w2'=>$w2,'w3'=>$w3,'loi_percentage'=>$loip,'remarks'=>$remark); + $loiid = $this->quality_model->saveTestReportLOIData($loitabledata); + + } + + $count =0; + foreach($afsphpdata as $afs) + { + $count++; + if($count != 12){ + $ssize = $afs['Sieve Size µm']; + $mesh_size = $afs['Mesh Size']; + $sandweight = $afs['Sand Weight']; + $Percentage = $afs['Percentage']; + $Multiplier = $afs['Multiplier']; + $Product = $afs['Product']; + $afstabledata = array('testreport_id'=>$MASTERID,'sieve_size'=>$ssize,'mesh_size'=>$mesh_size,'sandweight'=>$sandweight,'percentage'=>$Percentage,'multiplier'=>$Multiplier,'product'=>$Product); + $afsid = $this->quality_model->saveTestReportAFSData($afstabledata); + } + } + + echo "Report Data Saved Successfully!"; + + + } + + + function addNewInward_Report() + { + $data['records'] = $this->quality_model->getIGRNOforReport(); + $data['reports'] = $this->quality_model->getIGRNOReport(); ; + $data['emplist'] = $this->quality_model->getEmplistforReport(); + $this->global['pageTitle'] = 'Siddharth : Inward Inspection'; + $this->loadViews("inward_report_create", $this->global,$data,NULL); + + } + + + function getIGRLineItemNo() + { + $igrno = $this->input->post('param1'); + $data['igrdetails'] = $this->quality_model->getIGRLineItemNo($igrno); + //print_r($data['igrdetails']); + echo json_encode($data['igrdetails']); + + } + + + function getIGRDetails() + { + $igrno = $this->input->post('param1'); + $igrlineitemno = $this->input->post('param2'); + $data['igrdetails'] = $this->quality_model->getIGRDataforReport($igrno,$igrlineitemno); + //print_r($data['igrdetails']); + echo json_encode($data['igrdetails']); + } + + function pageNotFound() + { + $this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found'; + + $this->loadViews("404", $this->global, NULL, NULL); + } + + function uploadFile() + { + + $pathinfo = pathinfo($_FILES['rfile']['name']); + $config['upload_path'] = 'uploads/QAD/'; + $config['allowed_types'] = '*'; + $filename = $_FILES['rfile']['name']; + $ext = end(explode('.',$filename)); + + $ext = strtolower($ext); + $fn = 'qad' . date('Y-m-d') . time() . '.' . $ext; + //print_r($fn);die(); + $config['file_name'] = $fn; + //echo $config['file_name']; + $this->load->library('upload',$config); + $this->upload->initialize($config); + + + if($this->upload->do_upload('rfile')) + { + $uploadData = $this->upload->data(); + $uploadfilename = $uploadData['file_name']; + return $uploadfilename; + + } + else + { + $error = array('error' => $this->upload->display_errors()); + $uploadfilename = ''; + print_r($error); + return null; + } + + } + + + + // start zoho API + + function zohobooks_api_fetch_all(){ + try{ + if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null) + { + // $ch=curl_init(); + $this->load->helper('zohobooks_fetch_api_helper'); + if($_GET['from'] != null && $_GET['to'] != null) + { + $date_today = $_GET['to']; + $date_yesterday = $_GET['from']; + } + else + { + $date_today = date('Y-m-d'); + $date_yesterday = date('Y-m-d',strtotime('-1 day',strtotime($date_today))); + } + $chk_acc_token_val = $this->Zohobook_model->get_data('zohobook_accesstoken','id' , 1); + $date = new DateTime($chk_acc_token_val[0]['created_at']); $date->add(new DateInterval('PT1H')); + $token = 0; + if ($date->format('Y-m-d h:i:s') > date('Y-m-d h:i:s')) { $token = $chk_acc_token_val[0]['token']; } + else { $token = generateNewToken(); $tokendata['token'] = $token; $this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken'); } + $result = getheringInvoiceDetails($date_today , $date_yesterday , $token); + // echo json_encode($result); + $headers_new = $result['headers_new']; + $res = json_decode($result['data'],true); + $inv_array = $res['invoices']; + foreach($inv_array as $inv){ + $invoice_id = $inv['invoice_id']; + if($invoice_id!==""){ + $organization_id = '655654572'; + $result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new); + $resall = json_decode($result2,true); + $res2[] = $resall['invoice']; + } + } + $insert_count = 0; + $update_count = 0; + foreach($res2 as $rs) + { + $gst_no = $rs['gst_no']; + $sku = $rs['line_items'][0]['sku']; + $invoice_number = $rs['invoice_number']; + $invoice_date = $rs['date']; + + $sql_invoice_chk = $this->Zohobook_model->ip_invoices($invoice_number , $invoice_date); + if($sql_invoice_chk <= 0) + { + $gst_no = $rs['gst_no']; + $sku = $rs['line_items'][0]['sku']; + $invoice_number = $rs['invoice_number']; + $invoice_date = $rs['date']; + $due_date = $rs['due_date']; + $item_price = $rs['line_items'][0]['rate']; + $item_order = $rs['line_items'][0]['item_order']; + $item_product_unit = $rs['line_items'][0]['unit']; + $item_name = $rs['line_items'][0]['name']; + $item_description = $rs['line_items'][0]['description']; + $item_quantity = $rs['line_items'][0]['quantity']; + // $batch_no = $rs['custom_fields'][5]['value']; + $batch_no = ""; + $invoice_time=$rs['created_time']; + $time_array = explode("T", $invoice_time); + $time_array = explode("+",$time_array[1]); + $invoice_time = $time_array[0]; + $status = $rs['status']; + + $vehicle_number = $rs['custom_field_hash']['cf_vehicle_number']; + $transport_mode =$rs['custom_field_hash']['cf_transport_mode']; + $purchase_order_date = $rs['custom_field_hash']['cf_purchase_order_date']; + $driver = $rs['custom_field_hash']['cf_driver']; + $place_of_supply = $rs['custom_field_hash']['cf_place_of_supply']; + + $cgst = $rs['taxes'][0]['tax_name']; + $sgst = $rs['taxes'][1]['tax_name']; + $cgst = $cgst[4]; + $sgst = $sgst[4]; + $cgst = $cgst.'.000'; + $getcgsttax = $this->Zohobook_model->ip_tax_rates($cgst); + if($getcgsttax) + { + $cgsttaxid = $getcgsttax[0]['tax_rate_id']; + log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst); + $cgst_data['tax_rate_percent'] = $cgst; + $getcgsttax = $this->Zohobook_model->insert($cgst_data,'ip_tax_rates'); + $cgsttaxid = $getcgsttax[0]['tax_rate_id']; + log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid); + } + + $sgst = $sgst.'.000'; + $getsgsttax = $this->Zohobook_model->ip_tax_rates($sgst); + if($getsgsttax) + { + $sgsttaxid = $getsgsttax[0]['tax_rate_id']; + log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst); + $sgst_data['tax_rate_percent'] = $sgst; + $getsgsttax = $this->Zohobook_model->insert($sgst_data,'ip_tax_rates'); + $sgsttaxid = $getsgsttax[0]['tax_rate_id']; + log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid); + } + + $item_subtotal = $rs['line_items'][0]['item_total']; + $item_tax_total = $rs['tax_total']; + $item_total = $rs['total']; + $item_sgst_amt = $rs['taxes'][1]['tax_amount']; + $item_cgst_amt = $rs['taxes'][0]['tax_amount']; + + $item_discount = 0.00; + $item_igst_amt = 0.00; + if($batch_no==""){ $batch_no = "";} + $gst_sql = $this->Zohobook_model->ip_clients($gst_no); + if($gst_sql) + { + $client_id = $gst_sql[0]['client_id']; + log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no); + $gst_no_data['client_tax_code'] = $gst_no; + $gst_sql = $this->Zohobook_model->insert($gst_no_data,'ip_clients'); + $client_id = $gst_sql[0]['tax_rate_id']; + log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id); + } + + $sku_sql = $this->Zohobook_model->ip_products($sku); + if($sku_sql) + { + $product_id = $sku_sql[0]['product_id']; + log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku); + $sku_data['product_name'] = $item_name; + $sku_data['product_description'] = $item_description; + $sku_data['sku'] = $sku; + $sku_sql = $this->Zohobook_model->insert($sku_data,'ip_products'); + $product_id = $sku_sql[0]['sku']; + log_message('error', 'sku'.$sku); + log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id); + } + + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } + $url_key = $randomString; + + $ip_invoices['user_id'] = 1; + $ip_invoices['client_id'] = $client_id; + $ip_invoices['invoice_group_id'] = 6; + $ip_invoices['invoice_status_id'] = 2; + $ip_invoices['invoice_date_created'] = $invoice_date; + $ip_invoices['invoice_time_created'] = $invoice_time; + $ip_invoices['invoice_date_due'] = $due_date; + $ip_invoices['invoice_number'] = $invoice_number; + $ip_invoices['invoice_url_key'] = $url_key; + $ip_invoices['receivedstatus'] = 'ST066'; + $ip_invoices['credit_status'] = 0; + $invoice_insert_id = $this->Zohobook_model->insert($ip_invoices,'ip_invoices'); + if($invoice_insert_id) + log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id); + else + log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id); + + $ip_invoice_items['invoice_id'] = $invoice_insert_id; + $ip_invoice_items['item_product_id'] = $product_id; + $ip_invoice_items['item_date_added'] = $invoice_date; + $ip_invoice_items['item_name'] = $item_name; + $ip_invoice_items['item_description'] = $item_description; + $ip_invoice_items['item_quantity'] = $item_quantity; + $ip_invoice_items['item_price'] = $item_price; + $ip_invoice_items['item_order'] = $item_order; + $ip_invoice_items['item_product_unit'] = $item_product_unit; + $ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid; + $ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid; + $item_insert_id = $this->Zohobook_model->insert($ip_invoice_items,'ip_invoice_items'); + if($item_insert_id) + log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); + else + log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); + + //tax amount -- ip_invoice_item_amounts - table + $ip_invoice_item_amounts['item_id'] = $item_insert_id; + $ip_invoice_item_amounts['item_subtotal'] = $item_subtotal; + $ip_invoice_item_amounts['item_tax_total'] = $item_tax_total; + $ip_invoice_item_amounts['item_total'] = $item_total; + $ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt; + $ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt; + $ip_invoice_item_amounts['item_discount'] = $item_discount; + $ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt; + $result_tax_amount_insert = $this->Zohobook_model->insert($ip_invoice_item_amounts,'ip_invoice_item_amounts'); + if($result_tax_amount_insert) + log_message('error', 'Data insert success DB : ip_invoice_item_amounts '); + else + log_message('error', 'Data insert failed DB : ip_invoice_item_amounts '); + + //custom fields insert + // batch_no + $ip_invoice_custom_b['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_b['invoice_custom_fieldid'] = 62; + $ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no; + $result_invoice_custom_insert = $this->Zohobook_model->insert($ip_invoice_custom_b,'ip_invoice_custom'); + if($result_invoice_custom_insert) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // vehicle_number + $ip_invoice_custom_v['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_v['invoice_custom_fieldid'] = 8; + $ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number; + $res_vehicle = $this->Zohobook_model->insert($ip_invoice_custom_v,'ip_invoice_custom'); + if($res_vehicle) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // transport_mode + $ip_invoice_custom_t['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_t['invoice_custom_fieldid'] = 7; + $ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode; + $res_transport_mode = $this->Zohobook_model->insert($ip_invoice_custom_t,'ip_invoice_custom'); + if($res_transport_mode) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // purchase_order_date + $ip_invoice_custom_p['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_p['invoice_custom_fieldid'] = 15; + $ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date; + $res_purchase_order_date =$this->Zohobook_model->insert($ip_invoice_custom_p,'ip_invoice_custom'); + if($res_purchase_order_date) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // driver + $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_d['invoice_custom_fieldid'] = 58; + $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver; + $res_driver = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); + if($res_driver) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + // place_of_supply + $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id; + $ip_invoice_custom_d['invoice_custom_fieldid'] = 10; + $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply; + $res_place = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom'); + if($res_place) + log_message('error', 'Data insert success DB : ip_invoice_custom '); + else + log_message('error', 'Data insert failed DB : ip_invoice_custom '); + $insert_count = $insert_count + 1; + } + else // update invoice status, especially for cancelled invoices + { + if($status == "void") + { + $sql_invoice_update['invoice_status_id'] = 5; + $sql_invoice_update = $this->Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices'); + if($sql_invoice_update) + { + log_message('error', 'Data update success DB : ip_invoices '); + } + else + { + log_message('error', 'Data update failed DB : ip_invoices '); + } + $update_count = $update_count + 1; + } + } + } + echo 'new invoice inserted count- '. $insert_count . '/'.'cancelled status updated count - ' . $update_count; + + // curl_close($ch); + } + } + catch (Exception $e) { + $data['err'] = $e->getMessage(); + $data['last_query'] = $this->db->last_query(); + $this->Zohobook_model->insert($data,'zohobook_api_err'); + log_message('ERROR', "Data insertion failed : " . $e->getMessage()); + + } + } + //end + // END zoho API + + + +} ?> \ No newline at end of file diff --git a/application/controllers/report.php b/application/controllers/report.php index 020c8c23..0df4f246 100644 --- a/application/controllers/report.php +++ b/application/controllers/report.php @@ -514,8 +514,8 @@ class report extends BaseController $PO= $this->input->post('id'); //$PONO= substr($PO,10); - $split_id = explode('-', $PO,2); - $PONO=$split_id[1]; + $split_id = explode('-', $PO,2); + $PONO=$split_id[1]; $data = $this->dahsboard_Model->getfile($PONO); // print_r( $data);die; @@ -535,10 +535,8 @@ class report extends BaseController //echo $PONO; die; $igrfile= $this->dahsboard_Model->getfiles($igr,$PONO); - print_r($igrfile); // $igrfile = $this->inwardgateregister_model->viewIGRFile($IGRNO); $billfile = $this->dahsboard_Model->viewIGRFile1($igr,$PONO); - print_r($billfile); $data = array_merge($igrfile,$billfile); diff --git a/application/controllers/requisitionform.php b/application/controllers/requisitionform.php index 1a045c32..26eb9c93 100644 --- a/application/controllers/requisitionform.php +++ b/application/controllers/requisitionform.php @@ -29,7 +29,6 @@ class requisitionform extends BaseController */ function requisitionlisting() { - log_message('error'," Requisition Listing Fns Called"); $this->global['pageTitle'] = 'Siddharth : Requisition Listing'; $userID = $this->session->userdata ( 'userId' ); @@ -52,7 +51,6 @@ class requisitionform extends BaseController function requisition() { - log_message('error'," Raise Requisition Fns Called"); $this->global['pageTitle'] = 'Siddharth : Raise Requisition'; $data['RequestType'] = $this->requistion_model->getConfigValue('C020'); @@ -60,7 +58,6 @@ class requisitionform extends BaseController $data['EmpList'] = $this->requistion_model->getAllEmployees(); $data['ServiceOption'] = $this->requistion_model->getConfigValue('C022'); $userID = $this->session->userdata ( 'userId' ); - log_message('error'," Raise Requisition userId ".$userID); $data['Emp'] = $this->requistion_model->getEmpIdByUserID($userID); @@ -355,7 +352,6 @@ class requisitionform extends BaseController function addNewRequistion() { - log_message('error'," add new Requisition Fns Called"); $this->form_validation->set_rules('RequestType','RequestType','trim|required'); $this->form_validation->set_rules('EmpID','EmpID','trim|required'); @@ -365,18 +361,17 @@ class requisitionform extends BaseController } else { - log_message('error'," add new Requisition GET[ID] ".$_GET['ID']); $Status= $_GET['ID']; + log_message('error'," add new Requisition GET[ID] ".$_GET['ID']); + $RequestType = strtoupper(trim($this->input->post('RequestType'))); $Requestedby = strtoupper(trim($this->input->post('EmpID'))); - log_message('error'," add new Requisition empid ".$Requestedby); $RequestedbyDept = $this->session->userdata ( 'DEPCode' ); $CostCenter = $this->input->post('CostCenter'); $CreateBy = $this->session->userdata ( 'userId' ); - $UpdatedBy = $this->session->userdata ( 'userId' ); $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createddt = $dt->format('Y-m-d H:i:s'); - + $UpdatedBy = $this->session->userdata ( 'userId' ); $DeletedRow = $this->input->post('txtDeletedRow'); $RowCount = $this->input->post('txtRowCount'); @@ -439,8 +434,8 @@ class requisitionform extends BaseController $Quantity = $this->input->post('Quantity'.$i); $OtherD = $this->input->post('otherD'.$i); - //$ReqDetails = array('ReqNo'=>$ReqNumber, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'MaterialDescription'=>$OtherD); - $ReqDetails = array('ReqNo'=>$ReqNumber, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'MaterialDescription'=>$OtherD,'UpdatedBy'=>$UpdatedBy); + // $ReqDetails = array('ReqNo'=>$ReqNumber, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'MaterialDescription'=>$OtherD); + $ReqDetails = array('ReqNo'=>$ReqNumber, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'MaterialDescription'=>$OtherD,'UpdatedBy'=>$UpdatedBy); $this->requistion_model->addRequistionDetails($ReqDetails,$ReqNumber); } diff --git a/application/controllers/user.php b/application/controllers/user.php index 4c18ad70..1d2f6c3c 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -1,1573 +1,1573 @@ -load->model('user_model'); - $this->load->model('dahsboard_Model'); - $this->load->library('form_validation'); - $this->load->model('costcenter_model'); - - $this->isLoggedIn(); - } - - /** - * This function used to load the first screen of the user - */ - public function index() - { - // echo 'dash'; - // print_r($this->session->userdata ( 'name' )); - log_message('ERROR','#####Dashboard session name : ' . $this->session->userdata ( 'name' )); - //print_r($this->dummy);//die(); - $this->global['pageTitle'] = 'Siddharth : Dashboard'; - - $this->load->model('employeedetails_model'); - - - $this->load->model('dahsboard_Model'); - - $data['EmpCount'] = $this->employeedetails_model->getEmployeeCount(); - - $data['totalpurchaseorder']=$this->dahsboard_Model->totalpurchaseorder(); - - //print_r( $data['totalpurchaseorder']); - $data['totalordervalue']=$this->dahsboard_Model->totalordervalue(); - $data['pendingpo']=$this->dahsboard_Model->pendingpo(); - // $data['totalserviceamount']=$this->dahsboard_Model->totalserviceamount(); - // $data['totalcapitalamount']=$this->dahsboard_Model->totalcapitalamount(); - // $data['totalimportamount']=$this->dahsboard_Model->totalimportamount(); - // $data['totalrevenueamount']=$this->dahsboard_Model->totalrevenueamount(); - - - // $data['totalservicepo']=$this->dahsboard_Model->totalservicepo(); - // $data['totalrevenuepo']=$this->dahsboard_Model->totalrevenuepo(); - $data['totalimportpo']=$this->dahsboard_Model->totalimportpo(); - //$data['totalcapitalpo']=$this->dahsboard_Model->totalcapitalpo(); - - $data['details']=$this->dahsboard_Model->reqdetail(); - - $data['pending_details']=$this->dahsboard_Model->req_pending(); - // $data['list']=$this->dahsboard_Model->req_list(); - - $data['serviceprogress']=$this->dahsboard_Model->serviceprogress(); - $data['revenueprogress']=$this->dahsboard_Model->revenueprogress(); - $data['importprogress']=$this->dahsboard_Model->importprogress(); - $data['capitalprogress']=$this->dahsboard_Model->capitalprogress(); - //month-wise area chart - $data['getTotalServicePoCount'] = $this->dahsboard_Model->getTotalServicePoCount(); - $data['getTotalimportPoCount'] = $this->dahsboard_Model->getTotalimportPoCount(); - $data['getTotalcapitalPoCount'] = $this->dahsboard_Model->getTotalcapitalPoCount(); - $data['getTotalrevenuePoCount'] = $this->dahsboard_Model->getTotalrevenuePoCount(); - - - //dashboard pie chart - $data['importbudgt'] = $this->dahsboard_Model->importbudgt(); - $data['servicebudgt'] = $this->dahsboard_Model->servicebudgt(); - $data['revenuebudgt'] = $this->dahsboard_Model->revenuebudgt(); - $data['capitalbud'] = $this->dahsboard_Model->capitalbud(); - $data['typebal'] = $this->dahsboard_Model->typebal(); - - - /* HR DASHBOARD Controller Start*/ - - - $data['totemp'] = $this->dahsboard_Model->totemp(); - $data['totloan'] = $this->dahsboard_Model->totloan(); - $data['totpay'] = $this->dahsboard_Model->totpay(); - $data['totrec'] = $this->dahsboard_Model->totrec(); - $data['emplist'] = $this->dahsboard_Model->emplist(); - //print_r($data['totemp']);die; - - - - - - - - - - $date = $this->input->post("id"); - $dates = date('Y-m'); - $date = $dates . '-01'; - // // // echo $date; - $dat = date('d', strtotime("-1 days")); - // //echo $date; - - $WH = 'WH' . date('j', strtotime("-1 days")); - - $yesterday = $this->dahsboard_Model->attyesterday($WH, $date); - //print_r($yesterday);die; - - - // echo $values; - //$data['today'] = sizeof($yesterday); - - - - - // $date = $this->input->post("id"); - // echo $date; - $daydate = date('Y-m',strtotime($date)); - //echo $date; die; - $daydate = $daydate . '-01'; - - - $yesterday = $this->dahsboard_Model->attyesterday($WH, $daydate); - // print_r($yesterday); - - - //$absEmp =array($absEmp); - $values = 0; - $absEmp = array(); - - //echo $value; die; - foreach ($yesterday as $weekda => $value) - { - // echo $value[$WH]; - - if ($value[$WH] == 0) - { - - $values++; - $absendId = $value['EmpID']; - $absendName = $value['FirstName']; - $absEmp [] = $absendId . "-" . $absendName; //absend empid and name list - } - } - - //print_r($absentName);die; - $data['today'] = sizeof($absEmp); - - $data['abs_name'] = $absEmp; - - $OT = 'OT' . date('j',strtotime($date)); - - $CUR_month = date('t'); - //echo $CUR_month; - //echo $daydate; - $toDayEmployee = $this->dahsboard_Model->yesterdayAllPersentEmpSalary($WH, $OT, $daydate); - //$EmpID = $toDayEmployee[0]->EmpID; - - //print_r($toDayEmployee); die; - - $EmpID = 0; - - $employeeSalary = 0; - - foreach ($toDayEmployee as $value) - { - $values = 0; - $totalothour = 0; - - if ($value[$WH] != 0) - { - - $totalothour = $value[$OT]; - //echo $totalothour;die; - $values = 1; - - //print_r($values); die; - $Empid = $value['EmpID']; - //print_r($value['EmpID']); - - $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); - - // echo $Empid; - // print_r($totalEmployeePersent); - - if(!empty($totalEmployeePersent)) - { - - $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; - $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; - $totalsalary = $totalEmployeePersent[0]->TotalSalary; - $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; - //$allowances =$totalEmployeePersent[0]->Allowances; - //echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary)); - //$Allowances = $allowances * $values; - $Food_Allowances = $dayFoodAmt * $values; - - $daySalary = $Basic_Pay / $CUR_month; - /**per day salary working hour**/ - //echo $daySalary.'
'; - - $dayHra = $HRA_Amount / $CUR_month; - /** per day hra amount **/ - //echo $dayHra.'
'; - - $onehoursSalary = ($daySalary + $dayHra) / 8; - /**one hour salay ot calculation**/ - if ($totalothour != 0) /** if ot not equal zero **/ - { - $totSalayOT = $totalothour * $onehoursSalary; - } - else - { - $totSalayOT = 0; - } - $currentDaySalary = $daySalary * $values; - /** current day salary working days calculation**/ - - - $currentDayHra = $dayHra * $values; - /** total working days hra calculations**/ - // echo $currentDayHra.'
'; - $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; - /** current date pf calculation**/ - if ($totalsalary <= 20000) - { - - $esiAmount = $currentDatePF * 1.75 / 100; - /** esiamount not elgiable for 20000 **/ - } - else - { - $esiAmount = 0; - } - $pfAmount = $currentDaySalary * 12 / 100; - /** pf amount per day**/ - - //echo $totalothour;die; - $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances; - $salaryInCurrentday = $salaryInCurrentdays - ($esiAmount + $pfAmount); - $employeeSalary += round($salaryInCurrentday); - - } - // echo $employeeSalary; - } - - } - - - //$salaryInCurrentday++; - - - $data['employeeSalary'] = $employeeSalary; - - - - $working = array(); - $overtime = array(); - //$holid = array(); - for ($i = 1; $i <= $dat; $i++) //echo $dat; die; - { - - - $Working [] = 'WH' . $i; - $overtime [] = 'OT' . $i; - - $CUR_month = date('t'); - // echo $CUR_month; die; - // foreach ($holiday as $value) - // { - // //$holid []= 'WH'.$value; - // if($i==$value) { - // $holid []=$value; - // } - // } - - } - //print_r($WH);die; - $WH = implode(",", $Working); - - - $OT = implode(",", $overtime); - $salarycurrentdate = array(); - - - - $toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $date); - - - $totalSalary = 0; - $working = explode(",", $WH); - $overtime = explode(",", $OT); - foreach ($toDayEmployee as $value) - { - $values = 0; - foreach ($working as $work) - { -// foreach ($overtime as $extra) { - - if ($value[$work] != 0 || $value['OT' . substr($work, 2)] != 0) - { - $totalothour = $value['OT' . substr($work, 2)]; - //echo $totalothour; - $values = 1; - - //print_r($values); die; - $Empid = $value['EmpID']; - //echo $Empid; - - $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); - if(!empty($totalEmployeePersent)) - { - - $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; - $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; - $totalsalary = $totalEmployeePersent[0]->TotalSalary; - $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; - //$allowances =$totalEmployeePersent[0]->Allowances; - - // $Allowances = $allowances * $values; - - - $Food_Allowances = $dayFoodAmt * $values; - - $daySalary = $Basic_Pay / $CUR_month; - /**per day salary working hour**/ - //echo $daySalary.'
'; - - $dayHra = $HRA_Amount / $CUR_month; - /** per day hra amount **/ - //echo $dayHra.'
'; - $onehoursSalary = ($daySalary + $dayHra) / 8; - /**one hour salay ot calculation**/ - if ($totalothour != 0) /** if ot not equal zero **/ - { - $totSalayOT = $totalothour * $onehoursSalary; - } - else - { - $totSalayOT = 0; - } - $currentDaySalary = $daySalary * $values; - /** current day salary working days calculation**/ - - - $currentDayHra = $dayHra * $values; - /** total working days hra calculations**/ - // echo $currentDayHra.'
'; - $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; - /** current date pf calculation**/ - if ($totalsalary <= 20000) - { - - $esiAmount = $currentDatePF * 1.75 / 100; - /** esiamount not elgiable for 20000 **/ - } else { - $esiAmount = 0; - } - $pfAmount = $currentDaySalary * 12 / 100; - /** pf amount per day**/ - - //echo $totalothour;die; - $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances ; - - $salaryInCurrentday = $salaryInCurrentdays -($esiAmount+$pfAmount); - $totalSalarys = $totalSalary + $salaryInCurrentday; - - $totalSalary = round($totalSalarys); -// $salarycurrentdate[] = $salaryInCurrentday;; - // echo 'totalSalary'; - } - - } - - } - } - $data['totalSalary'] = $totalSalary; - // print_r( 'totalSalary');die; - - - $this->loadViews("dashboard", $this->global, $data, NULL); - } - -/*date click on day salary,absent name, total absent display*/ - -function dateFunctionChangeVales() -{ - - - - $date = $this->input->post("id"); - $dates = date('Y-m'); - $date = $dates . '-01'; - // // echo $date; - // $dat = date('d', strtotime("-1 days")); - //echo $date; - - $WH = 'WH' . date('j', strtotime("-1 days")); - - //echo($WH); - $yesterday = $this->dahsboard_Model->attyesterday($WH, $date); - //print_r($yesterday);die; - $values = 0; - foreach ($yesterday as $weekda => $value) - { - - if ($value[$WH] == 0) - { - - $values++; - } - - - } - // echo $values; - $data['values'] = $values; - - - - - $date = $this->input->post("id"); - // echo $date; - $daydate = date('Y-m',strtotime($date)); - //echo $date; die; - $daydate = $daydate . '-01'; - //$dat = date('d'); - // echo $daydate; echo ""; - $WH = 'WH' . date('j',strtotime($date)); - // echo $WH; - - $yesterday = $this->dahsboard_Model->attyesterday($WH, $daydate); - // print_r($yesterday); - - - //$absEmp =array($absEmp); - $values = 0; - $absEmp = array(); - //echo $value; die; - foreach ($yesterday as $weekda => $value) - { - // echo $value[$WH]; - - if ($value[$WH] == 0) - { - - $values++; - $absendId = $value['EmpID']; - $absendName = $value['FirstName']; - $absEmp [] = $absendId . "-" . $absendName; //absend empid and name list - } - } - - //print_r($absentName);die; - $data['today'] = $values; - $data['absname'] = $absEmp; - - $OT = 'OT' . date('j',strtotime($date)); - - $CUR_month = date('t'); - //echo $CUR_month; - //echo $daydate; - $toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $daydate); - //$EmpID = $toDayEmployee[0]->EmpID; - - //print_r($toDayEmployee); die; - - $EmpID = 0; - - $employeeSalary = 0; - - foreach ($toDayEmployee as $value) - { - $values = 0; - $totalothour = 0; - - if ($value[$WH] != 0) - { - - $totalothour = $value[$OT]; - //echo $totalothour;die; - $values = 1; - - //print_r($values); die; - $Empid = $value['EmpID']; - //print_r($value['EmpID']); - - $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); - - // echo $Empid; - // print_r($totalEmployeePersent); - - if(!empty($totalEmployeePersent)) - { - - $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; - $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; - $totalsalary = $totalEmployeePersent[0]->TotalSalary; - $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; - //$allowances =$totalEmployeePersent[0]->Allowances; - //echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary)); - //$Allowances = $allowances * $values; - $Food_Allowances = $dayFoodAmt * $values; - - $daySalary = $Basic_Pay / $CUR_month; - /**per day salary working hour**/ - //echo $daySalary.'
'; - - $dayHra = $HRA_Amount / $CUR_month; - /** per day hra amount **/ - //echo $dayHra.'
'; - - $onehoursSalary = ($daySalary + $dayHra) / 8; - /**one hour salay ot calculation**/ - if ($totalothour != 0) /** if ot not equal zero **/ - { - $totSalayOT = $totalothour * $onehoursSalary; - } else { - $totSalayOT = 0; - } - $currentDaySalary = $daySalary * $values; - /** current day salary working days calculation**/ - - - $currentDayHra = $dayHra * $values; - /** total working days hra calculations**/ - // echo $currentDayHra.'
'; - $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; - /** current date pf calculation**/ - if ($totalsalary <= 20000) - { - - $esiAmount = $currentDatePF * 1.75 / 100; - /** esiamount not elgiable for 20000 **/ - } else { - $esiAmount = 0; - } - $pfAmount = $currentDaySalary * 12 / 100; - /** pf amount per day**/ - - //echo $totalothour;die; - $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances; - $salaryInCurrentday = $salaryInCurrentdays - ($esiAmount + $pfAmount); - $employeeSalary += round($salaryInCurrentday); - - } - // echo $employeeSalary; - } - - } - - - //$salaryInCurrentday++; - - - $data['employeeSalary'] = $employeeSalary; - - $working = array(); - $overtime = array(); - //$holid = array(); - $len = date('d',strtotime($date)); - for ($i = 1; $i <= $len; $i++) //echo $dat; die; - { - - - $Working [] = 'WH' . $i; - $overtime [] = 'OT' . $i; - - $CUR_month = date('t'); - // echo $CUR_month; die; - // foreach ($holiday as $value) - // { - // //$holid []= 'WH'.$value; - // if($i==$value) { - // $holid []=$value; - // } - // } - - } - //print_r($Working);die; - $WH = implode(",", $Working); - - - $OT = implode(",", $overtime); - $salarycurrentdate = array(); - - - - $toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $daydate); - - - $totalSalary = 0; - $working = explode(",", $WH); - $overtime = explode(",", $OT); - foreach ($toDayEmployee as $value) - { - $values = 0; - foreach ($working as $work) - { -// foreach ($overtime as $extra) { - - if ($value[$work] != 0 || $value['OT' . substr($work, 2)] != 0) - { - $totalothour = $value['OT' . substr($work, 2)]; - //echo $totalothour; - $values = 1; - - //print_r($values); die; - $Empid = $value['EmpID']; - //echo $Empid; - - $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); - if(!empty($totalEmployeePersent)) - { - - $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; - $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; - $totalsalary = $totalEmployeePersent[0]->TotalSalary; - $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; - //$allowances =$totalEmployeePersent[0]->Allowances; - - // $Allowances = $allowances * $values; - - - $Food_Allowances = $dayFoodAmt * $values; - - $daySalary = $Basic_Pay / $CUR_month; - /**per day salary working hour**/ - //echo $daySalary.'
'; - - $dayHra = $HRA_Amount / $CUR_month; - /** per day hra amount **/ - //echo $dayHra.'
'; - $onehoursSalary = ($daySalary + $dayHra) / 8; - /**one hour salay ot calculation**/ - if ($totalothour != 0) /** if ot not equal zero **/ - { - $totSalayOT = $totalothour * $onehoursSalary; - } - else - { - $totSalayOT = 0; - } - $currentDaySalary = $daySalary * $values; - /** current day salary working days calculation**/ - - - $currentDayHra = $dayHra * $values; - /** total working days hra calculations**/ - // echo $currentDayHra.'
'; - $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; - /** current date pf calculation**/ - if ($totalsalary <= 20000) - { - - $esiAmount = $currentDatePF * 1.75 / 100; - /** esiamount not elgiable for 20000 **/ - } else { - $esiAmount = 0; - } - $pfAmount = $currentDaySalary * 12 / 100; - /** pf amount per day**/ - - //echo $totalothour;die; - $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances ; - - $salaryInCurrentday = $salaryInCurrentdays -($esiAmount+$pfAmount); - $totalSalarys = $totalSalary + $salaryInCurrentday; - - $totalSalary = round($totalSalarys); -// $salarycurrentdate[] = $salaryInCurrentday;; - // echo 'totalSalary'; - } - - } - - } - } - $data['totalSalary'] = $totalSalary; - - //print_r($data['totalSalary']);die; - // } - echo json_encode($data); -} - - -/*this function uesd to finance startdate */ - - public function getFinancialStartDate() - { - - - - $CURMONTH = date('n'); - $CURYEAR = date('Y'); - $FINYEAR = 0; - if ($CURMONTH >= 4) - { - $FINYEAR = $CURYEAR; - } else - { - $FINYEAR = $CURYEAR - 1; - } - - $dateInString = $FINYEAR . '-4-1'; - $result = date_create($dateInString); - // print_r($result); - - return $result; - -} - - -/*this function uesd to finance EndDate */ - public function getFinancialEndDate() - { - $CURMONTH = date('n'); - $CURYEAR = date('Y'); - $FINYEAR = 0; - if ($CURMONTH < 4) - { - $FINYEAR = $CURYEAR; - } else - { - $FINYEAR = $CURYEAR + 1; - } - - $dateInString = $FINYEAR . '-3-31'; - $result = date_create($dateInString); - - - // print_r($result); - return $result; - - - } - - - - /*this function used to speedometer month emp performances display*/ - - function monthattendance($empID ='') -{ - - $date = date('Y-m'); - //echo $date; - $dates = $date . '-01'; - $EmpID = ''; - if(empty($empID)){ - $EmpID = $this->input->post('id'); - } - else - { - $EmpID = $empID; - } - // echo $EmpID;die; - $monthabs = $this->dahsboard_Model->attendance($EmpID, $dates); - $persent_month = date('t');//current month of days 31 - $values = array(); - $otvalues = array(); - - $weekdays = array(); - $otHours = array(); - $date = date('j');//current month current date - - - $CURDATE =date('d');//current month current date - - $CUR_month = date('t'); //current month of days 31 - - - $CURYEAR = date('Y'); - $CURMONTH = date('m'); - - $datejoin = $this->dahsboard_Model->joindate($EmpID); - $DateofJoiningInString = $datejoin[0]->DateofJoining; - $DateofJoining = date_create($DateofJoiningInString); - $doj_month = date_format($DateofJoining, "n"); - $doj_year = date_format($DateofJoining, "Y"); - $doj_day = date_format($DateofJoining, "j"); - //echo $doj_day; - for ($i = 1; $i <= $persent_month; $i++) - { - $weekdays[] = 'WH' . $i; - $otHours[] = 'OT' . $i; - } - $totalwhhours=0; - foreach ($monthabs as $weekda) - { - //print_r($weekda); - foreach ($weekda as $key => $value) - { - //print_r($key); - foreach ($weekdays as $weeks) - { - if ($weeks == $key) - { - //print_r($key); - if ($value != 0) - { - //echo $value; - $values[] = $value; - - } - //echo $values; - } - - } - foreach ($otHours as $ot) - { - if ($ot == $key) - { - if ($value != 0) - { - $otvalues [] = $value; - - } - - } - } - - } - } - - - $totalothour = array_sum($otvalues); - //$totalwhhour = sizeof($values); - $totalwhhours = array_sum($values); - - $totalwhhour = $totalwhhours/8; - //echo $totalwhhour; - if ($CURMONTH == $doj_month && $CURYEAR == $doj_year) - { - //echo $doj_day; - $data['CUR_month'] = $CURDATE - $doj_day + 1; - //print_r($month); - } - else - { - $data['CUR_month'] = $date; - } - - if ($totalwhhour != 0) - { - $year = date('Y'); - $current_month = date('m'); - - $data['values'] = $totalwhhour; - //$data['salaryInCurrentday'] = round($salaryInCurrentday); - $data['present_percentage'] = round(($totalwhhour / $data['CUR_month']) * 100); - - } - - else { - - $data['values'] = 0; - //$data['salaryInCurrentday'] = 0; - $data['present_percentage'] = 0; - - } - if(empty($empID)){ - echo json_encode( $data); - } - else{ - return $data; - } - } - - - - - - - - /*this function used to speedometer year emp performances display*/ - -function attendanceyear($empID ='') -{ - - $CURMONTH = date('m'); - $CURDATE = date('d'); - $CURYEAR = date('Y'); - $EmpID = ''; - if(empty($empID)) - { - $EmpID = $this->input->post('id'); - } - else - { - $EmpID = $empID; - } - - $day = array(); - $datejoin = $this->dahsboard_Model->joindate($EmpID); - - $DateofJoiningInString = $datejoin[0]->DateofJoining; - $DateofJoining = date_create($DateofJoiningInString); - // print_r($DateofJoining); - $doj_month = date_format($DateofJoining, "n"); - $doj_year = date_format($DateofJoining, "Y"); - $doj_day = date_format($DateofJoining, "j"); - - $finStart = $this->getFinancialStartDate(); - $finEnd = $this->getFinancialEndDate(); - - $JoinedMonth = date_format($DateofJoining, "n"); - - // print_r($finStart);print_r($finEnd); - //print $JoinedMonth; - - if ($DateofJoining >= $finStart && $DateofJoining <= $finEnd) - { - $JoinedMonthAttendance = $this->dahsboard_Model->getAllAttendances($EmpID,$JoinedMonth); - $joinedMonthDaysCount = cal_days_in_month(CAL_GREGORIAN, $doj_month, $doj_year); - - if ($CURMONTH == $doj_month && $CURYEAR == $doj_year) - { - $joinedMonthWorkingDayCount = $CURDATE - $doj_day +1 ; - } - else - { - $joinedMonthWorkingDayCount = $joinedMonthDaysCount - $doj_day +1; - } - - $joinedMonthDays = 0; - for ($j = $doj_day; $j <= $joinedMonthDaysCount; $j++) - { - $weekdays[] = 'WH' . $j; - } - foreach ($JoinedMonthAttendance as $day) - { - foreach ($day as $key => $value) - { - foreach ($weekdays as $weeks) - { - if ($weeks == $key) - { - if ($value != 0) - { - // echo $value; - $joinedMonthDays++; - } - } - - } - } - - } - - //echo $joinedMonthDays;die; - - $result = $this->dahsboard_Model->attendanceyear($EmpID, $JoinedMonth + 1); - - //print_r($result); - $yearabs = $this->dahsboard_Model->getAllAttendance($EmpID, $CURMONTH); - $TotalNoofDays = $result[0]->TotalWorkingDays; - $DaysWorked = $result[0]->DaysWorked; - - // echo $TotalNoofDays; - // echo $DaysWorked;die; - $values = 0; - $values = array(); - $weekdays = array(); - $date = date('d'); - - $Work = array_sum($weekdays); - - for ($j = 1; $j <= $date; $j++) - { - $weekdays[] = 'WH' . $j; - } - $totalhours =0; - foreach ($yearabs as $day) - { - foreach ($day as $key => $value) - { - foreach ($weekdays as $weeks) - { - if ($weeks == $key) - { - if ($value != 0) - { - //$values++; - //$totalhours = array_sum($value); - $values[] = $value; - - } - } - - } - } - } - - $DaysWorked = 0; - - $totalhours = array_sum($values); - - $values = $totalhours/8; - //print_r($totalhours); - - if ($CURMONTH == $doj_month && $CURYEAR == $doj_year) - { - $TotalNoofDays = $TotalNoofDays + $joinedMonthWorkingDayCount; - $DaysWorked = $joinedMonthDays; - } - else - { - $TotalNoofDays = $TotalNoofDays + $CURDATE + $joinedMonthWorkingDayCount; - $DaysWorked = $DaysWorked + $joinedMonthDays + $values; - } - - - - - $final_res = round(($DaysWorked / $TotalNoofDays) * 100); - // echo "------"; - //echo $final_res;exit(); - $data['workeds'] = $DaysWorked; - $data['yeardata'] = $final_res; - $data['totaldays'] = $TotalNoofDays; - - } - - else - { - $result = $this->dahsboard_Model->attendanceyear($EmpID, 4); - $yearabs = $this->dahsboard_Model->getAllAttendance($EmpID, $CURMONTH); - $TotalNoofDays = $result[0]->TotalWorkingDays; - $DaysWorked = $result[0]->DaysWorked; - - - $values = 0; - $values = array(); - $weekdays = array(); - $date = date('d'); - - $Work = array_sum($weekdays); - - for ($j = 1; $j <= $date; $j++) - { - $weekdays[] = 'WH' . $j; - } - foreach ($yearabs as $day) - { - foreach ($day as $key => $value) - { - foreach ($weekdays as $weeks) - { - if ($weeks == $key) - { - if ($value != 0) - { - - $values[]=$value; - } - } - - } - } - } - - $totalhours = array_sum($values); - - $values = $totalhours/8; - - $TotalNoofDays = $TotalNoofDays + $CURDATE; - $DaysWorked = $DaysWorked + $values; - $final_res = round(($DaysWorked / $TotalNoofDays) * 100); - // echo "------"; - //echo $final_res;exit(); - $data['workeds'] = $DaysWorked; - $data['yeardata'] = $final_res; - $data['totaldays'] = $TotalNoofDays; - - - } - - if(empty($empID)) - { - - echo json_encode($data); - } - else - { - return $data; - } -} - - - - - - - - - - - -/****************HR DASHBOART Controller END **************************************/ - - /** - * This function is used to load the user list - */ - function userListing() - { - // if($this->isAdmin() == TRUE) - // { - // $this->loadThis(); - // } - // else - // { - - $data['userRecords'] = $this->user_model->userListing(); - - $this->global['pageTitle'] = 'Siddharth : User Listing'; - - $this->loadViews("users", $this->global, $data, NULL); - //} - } - - - /** - * This function is used to load the add new form - */ - function addNew() - { - // if($this->isAdmin() == TRUE) - // { - // $this->loadThis(); - // } - // else - // { - $data['EmpList'] = $this->user_model->getAllEmployees(); - - $data['roles'] = $this->user_model->getUserRoles(); - - $data['Department'] = $this->costcenter_model->getDepartment(); - - $this->global['pageTitle'] = 'Siddharth : Add New User'; - - $this->loadViews("addNew", $this->global, $data, NULL); - // } - } - - /** - * This function is used to check whether email already exist or not - */ - function checkEmailExists() - { - $userId = $this->input->post("userId"); - $email = $this->input->post("email"); - - if(empty($userId)){ - $result = $this->user_model->checkEmailExists($email); - } else { - $result = $this->user_model->checkEmailExists($email, $userId); - } - - if(empty($result)){ echo("true"); } - else { echo("false"); } - } - /* Validation for Employee Dropdown - */ - function Employee_validate($selectValue) -{ - //echo 'select_validate method called'; - // 'none' is the first option and the text says something like "-Choose one-" - if($selectValue == '0') - { - $this->form_validation->set_message('Employee_validate', 'Please Select Employee.'); - return false; - } - else // user picked something - { - return true; - } -} - /* Validation for Employee Dropdown - */ - function Role_validate($selectValue) -{ - //echo 'select_validate method called'; - // 'none' is the first option and the text says something like "-Choose one-" - if($selectValue == '0') - { - $this->form_validation->set_message('Role_validate', 'Please Select Role.'); - return false; - } - else // user picked something - { - return true; - } -} - /** - * This function is used to add new user to the system - */ - function addNewUser() - { - // if($this->isAdmin() == TRUE) - // { - // $this->loadThis(); - // } - // else - // { - - $this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS'); - // $this->form_validation->set_rules('role','role','trim|callback_Role_validate'); - $this->form_validation->set_rules('password','Password','required|max_length[20]'); - $this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]'); - - - if($this->form_validation->run() == FALSE) - { - $this->addNew(); - } - else - { - $EmpID = $this->input->post('EmpList'); - $roleId = '2'; - $password = $this->input->post('password'); - $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); - $Createddt = $dt->format('Y-m-d H:i:s'); - - $email = $this->input->post('MailID'); - - $SelectedDepartment = $this->input->post('txtSelectedDepartment'); - - $comma_separated = explode(':', $SelectedDepartment); - - - - - - - $userInfo = array('email'=>$email,'EmpID'=>$EmpID,'password'=>getHashedPassword($password),'roleId'=>$roleId,'createdBy'=>$this->vendorId,'createdDtm'=>$Createddt); - - - - //die(); - - $result = $this->user_model->addNewUser($userInfo); - - if($SelectedDepartment != '') - { - - for ($j = 0; $j < count($comma_separated); $j++) - { - $DeptCode = $comma_separated[$j]; - - //echo $DeptCode; - - $userdept=array('EmpID'=>$EmpID,'Departmentcode'=>$DeptCode); - - //print_r($userdept); - - $access= $this->user_model->addAccess($userdept); - - //echo $access; - } - } - - - if($result > 0) - { - - - echo ""; - redirect('userListing','refresh'); - - } - - else - { - - redirect('userListing','refresh'); - echo ""; - } - - } - //} - } - - - - - -function Adduserdepartment() - { - $empid= $this->input->post('Eid'); - $Depcode= $this->input->post('Department'); - $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); - - $access= $this->user_model->addAccess($userdept); - if($access>0) - { - echo "Successfully Added"; - } - } - - - function Deleteuserdepartment() - { - $empid= $this->input->post('Eid'); - $Depcode= $this->input->post('Department'); - $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); - - $access= $this->user_model->DeleteAccess($empid,$Depcode); - - if($access>0) - { - echo "Successfully Deleted"; - } - - } - - - /** - * This function is used load user edit information - * @param number $userId : Optional : This is user id - */ - function editOld($UserId = '') - { - // if($this->isAdmin() == TRUE ) - // { - // $this->loadThis(); - // } - // else - // { - if($UserId == '') - { - // redirect('userListing'); - } - - $Uid = $_GET['UID']; - $Empid = $_GET['EMPID']; - - - $data['roles'] = $this->user_model->getUserRoles(); - - //print_r($data); - - $data['EmpList'] = $this->user_model->GetEmployeeDetails($Uid); - //print_r($data); - $data['Departmentlist'] = $this->costcenter_model->getDepartmentnotadded($Empid); - $data['EmpRole'] = $this->user_model->GetRoleNameByUserID($Uid); - $data['AccessDept'] = $this->costcenter_model ->getaccessDept($Empid); - - // $data['userInfo'] = $this->user_model->getUserInfo($userId); - - $this->global['pageTitle'] = 'Siddharth : Edit User'; - - $this->loadViews("editOld", $this->global, $data, NULL); - //} - } - - - /** - * This function is used to edit the user information - */ - function editUser() - { - // if($this->isAdmin() == TRUE) - // { - // $this->loadThis(); - // } - // else - // { - $userId = $this->input->post('EmpList'); - $this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS'); - $this->form_validation->set_rules('role','role','trim|callback_Role_validate'); - $this->form_validation->set_rules('password','Password','required|max_length[20]'); - $this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]'); - - if($this->form_validation->run() == FALSE) - { - $this->editOld($userId); - } - else - { - $EmpID = $this->input->post('EmpList'); - $role = $this->input->post('role'); - $password = $this->input->post('password'); - $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); - $updatedDate = $dt->format('Y-m-d H:i:s'); - - // echo $EmpID; - - $userInfo = array(); - - - $userInfo = array('password'=>getHashedPassword($password),'roleId'=>$role,'EmpId'=>$EmpID,'updatedDtm'=>$updatedDate); - - - - - $result = $this->user_model->editUser($userInfo, $EmpID); - - if($result == true) - { - $this->session->set_flashdata('success', 'User updated successfully'); - } - else - { - $this->session->set_flashdata('error', 'User updation failed'); - } - - redirect('userListing'); - } - //} - } - - - /** - * This function is used to delete the user using userId - * @return boolean $result : TRUE / FALSE - */ - function deleteUser() - { - echo 'Delete'; - $Uid = $this->input->post('id'); - - $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); - $updatedDate = $dt->format('Y-m-d H:i:s'); - - $userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>$updatedDate); - - $result = $this->user_model->deleteUser($Uid, $userInfo); - - echo 'Succssfully change the user status to InAcive'; - - } - - /** - * This function is used to load the change password screen - */ - function loadChangePass() - { - $this->global['pageTitle'] = 'Siddharth : Change Password'; - - $this->loadViews("changePassword", $this->global, NULL, NULL); - } - - - /** - * This function is used to change the password of the user - */ - function changePassword() - { - $this->load->library('form_validation'); - - $this->form_validation->set_rules('oldPassword','Old password','required|max_length[20]'); - $this->form_validation->set_rules('newPassword','New password','required|max_length[20]'); - $this->form_validation->set_rules('cNewPassword','Confirm new password','required|matches[newPassword]|max_length[20]'); - - if($this->form_validation->run() == FALSE) - { - $this->loadChangePass(); - } - else - { - $oldPassword = $this->input->post('oldPassword'); - $newPassword = $this->input->post('newPassword'); - - $resultPas = $this->user_model->matchOldPassword($this->vendorId, $oldPassword); - - if(empty($resultPas)) - { - $this->session->set_flashdata('nomatch', 'Your old password not correct'); - redirect('loadChangePass'); - } - else - { - $usersData = array('password'=>getHashedPassword($newPassword), 'updatedBy'=>$this->vendorId, - 'updatedDtm'=>date('Y-m-d H:i:sa')); - - $result = $this->user_model->changePassword($this->vendorId, $usersData); - - if($result > 0) { $this->session->set_flashdata('success', 'Password updation successful'); } - else { $this->session->set_flashdata('error', 'Password updation failed'); } - - redirect('loadChangePass'); - } - } - } - - function pageNotFound() - { - $this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found'; - - $this->loadViews("404", $this->global, NULL, NULL); - } - //this function used to delivery performances - -function deliver_perform() -{ - - - $this->global['pageTitle'] = 'Siddharth : Delivery Performance'; - if ($this->input->post('btn_submit')) { - - $ab=$this->input->post('financialyear'); - - $fa=substr($ab,0,-5); - $aa=substr($ab,5,5); - $m=$this->input->post('month'); - - //print_r($prod); - //die; - - $data['fy']=$this->user_model->fincalYear(); - $data['per']=$this->user_model->deliver_perform($fa,$aa,$m); - - // // print_r( $data['spurchse']); - } - - $data['fy']=$this->user_model->fincalYear(); - - $this->loadviews("deliver_perform",$this->global,$data,NULL); - - -} - /* - *favourite add function and load view - */ - - function favourite() - { - $this->global['pageTitle'] = 'Siddharth :Favourite '; - - - // $data['ponoreset']=$this->purchaseorder_model->ponoresetfinyear(); - - - $this->loadViews("Favourite", $this->global,Null); - - } - function favouriteadd() - { - $name = $this->input->post('name'); - $url = $this->input->post('url'); - $status = $this->input->post('status'); - $CreateBy = $this->session->userdata ( 'userId' ); - - $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); - $createddt = $dt->format('Y-m-d H:i:s'); - $menu = $this->input->post('menu'); - // $RowCount = $this->input->post('txtRowCount'); - // $DeletedRow = $this->input->post('txtDeletedRow'); - // $comma_separated = explode(':', $DeletedRow); - $favourite = array('Menu_Name'=>$name,'Menu_URL'=>$url,'Status'=>$status,'Created_BY'=>$CreateBy,'Created_ON'=>$createddt,'Menu_ID'=>$menu); - $getdata= $this->user_model->favouriteadd($favourite); - // print_r($favourite); - // die(); - if($getdata==1) - - { - echo"success"; - - } - else{ - echo"failed"; - } - - } -} - -?> +load->model('user_model'); + $this->load->model('dahsboard_Model'); + $this->load->library('form_validation'); + $this->load->model('costcenter_model'); + + $this->isLoggedIn(); + } + + /** + * This function used to load the first screen of the user + */ + public function index() + { + // echo 'dash'; + // print_r($this->session->userdata ( 'name' )); + log_message('ERROR','#####Dashboard session name : ' . $this->session->userdata ( 'name' )); + //print_r($this->dummy);//die(); + $this->global['pageTitle'] = 'Siddharth : Dashboard'; + + $this->load->model('employeedetails_model'); + + + $this->load->model('dahsboard_Model'); + + $data['EmpCount'] = $this->employeedetails_model->getEmployeeCount(); + + $data['totalpurchaseorder']=$this->dahsboard_Model->totalpurchaseorder(); + + //print_r( $data['totalpurchaseorder']); + $data['totalordervalue']=$this->dahsboard_Model->totalordervalue(); + $data['pendingpo']=$this->dahsboard_Model->pendingpo(); + // $data['totalserviceamount']=$this->dahsboard_Model->totalserviceamount(); + // $data['totalcapitalamount']=$this->dahsboard_Model->totalcapitalamount(); + // $data['totalimportamount']=$this->dahsboard_Model->totalimportamount(); + // $data['totalrevenueamount']=$this->dahsboard_Model->totalrevenueamount(); + + + // $data['totalservicepo']=$this->dahsboard_Model->totalservicepo(); + // $data['totalrevenuepo']=$this->dahsboard_Model->totalrevenuepo(); + $data['totalimportpo']=$this->dahsboard_Model->totalimportpo(); + //$data['totalcapitalpo']=$this->dahsboard_Model->totalcapitalpo(); + + $data['details']=$this->dahsboard_Model->reqdetail(); + + $data['pending_details']=$this->dahsboard_Model->req_pending(); + // $data['list']=$this->dahsboard_Model->req_list(); + + $data['serviceprogress']=$this->dahsboard_Model->serviceprogress(); + $data['revenueprogress']=$this->dahsboard_Model->revenueprogress(); + $data['importprogress']=$this->dahsboard_Model->importprogress(); + $data['capitalprogress']=$this->dahsboard_Model->capitalprogress(); + //month-wise area chart + $data['getTotalServicePoCount'] = $this->dahsboard_Model->getTotalServicePoCount(); + $data['getTotalimportPoCount'] = $this->dahsboard_Model->getTotalimportPoCount(); + $data['getTotalcapitalPoCount'] = $this->dahsboard_Model->getTotalcapitalPoCount(); + $data['getTotalrevenuePoCount'] = $this->dahsboard_Model->getTotalrevenuePoCount(); + + + //dashboard pie chart + $data['importbudgt'] = $this->dahsboard_Model->importbudgt(); + $data['servicebudgt'] = $this->dahsboard_Model->servicebudgt(); + $data['revenuebudgt'] = $this->dahsboard_Model->revenuebudgt(); + $data['capitalbud'] = $this->dahsboard_Model->capitalbud(); + $data['typebal'] = $this->dahsboard_Model->typebal(); + + + /* HR DASHBOARD Controller Start*/ + + + $data['totemp'] = $this->dahsboard_Model->totemp(); + $data['totloan'] = $this->dahsboard_Model->totloan(); + $data['totpay'] = $this->dahsboard_Model->totpay(); + $data['totrec'] = $this->dahsboard_Model->totrec(); + $data['emplist'] = $this->dahsboard_Model->emplist(); + //print_r($data['totemp']);die; + + + + + + + + + + $date = $this->input->post("id"); + $dates = date('Y-m'); + $date = $dates . '-01'; + // // // echo $date; + $dat = date('d', strtotime("-1 days")); + // //echo $date; + + $WH = 'WH' . date('j', strtotime("-1 days")); + + $yesterday = $this->dahsboard_Model->attyesterday($WH, $date); + //print_r($yesterday);die; + + + // echo $values; + //$data['today'] = sizeof($yesterday); + + + + + // $date = $this->input->post("id"); + // echo $date; + $daydate = date('Y-m',strtotime($date)); + //echo $date; die; + $daydate = $daydate . '-01'; + + + $yesterday = $this->dahsboard_Model->attyesterday($WH, $daydate); + // print_r($yesterday); + + + //$absEmp =array($absEmp); + $values = 0; + $absEmp = array(); + + //echo $value; die; + foreach ($yesterday as $weekda => $value) + { + // echo $value[$WH]; + + if ($value[$WH] == 0) + { + + $values++; + $absendId = $value['EmpID']; + $absendName = $value['FirstName']; + $absEmp [] = $absendId . "-" . $absendName; //absend empid and name list + } + } + + //print_r($absentName);die; + $data['today'] = sizeof($absEmp); + + $data['abs_name'] = $absEmp; + + $OT = 'OT' . date('j',strtotime($date)); + + $CUR_month = date('t'); + //echo $CUR_month; + //echo $daydate; + $toDayEmployee = $this->dahsboard_Model->yesterdayAllPersentEmpSalary($WH, $OT, $daydate); + //$EmpID = $toDayEmployee[0]->EmpID; + + //print_r($toDayEmployee); die; + + $EmpID = 0; + + $employeeSalary = 0; + + foreach ($toDayEmployee as $value) + { + $values = 0; + $totalothour = 0; + + if ($value[$WH] != 0) + { + + $totalothour = $value[$OT]; + //echo $totalothour;die; + $values = 1; + + //print_r($values); die; + $Empid = $value['EmpID']; + //print_r($value['EmpID']); + + $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); + + // echo $Empid; + // print_r($totalEmployeePersent); + + if(!empty($totalEmployeePersent)) + { + + $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; + $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; + $totalsalary = $totalEmployeePersent[0]->TotalSalary; + $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; + //$allowances =$totalEmployeePersent[0]->Allowances; + //echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary)); + //$Allowances = $allowances * $values; + $Food_Allowances = $dayFoodAmt * $values; + + $daySalary = $Basic_Pay / $CUR_month; + /**per day salary working hour**/ + //echo $daySalary.'
'; + + $dayHra = $HRA_Amount / $CUR_month; + /** per day hra amount **/ + //echo $dayHra.'
'; + + $onehoursSalary = ($daySalary + $dayHra) / 8; + /**one hour salay ot calculation**/ + if ($totalothour != 0) /** if ot not equal zero **/ + { + $totSalayOT = $totalothour * $onehoursSalary; + } + else + { + $totSalayOT = 0; + } + $currentDaySalary = $daySalary * $values; + /** current day salary working days calculation**/ + + + $currentDayHra = $dayHra * $values; + /** total working days hra calculations**/ + // echo $currentDayHra.'
'; + $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; + /** current date pf calculation**/ + if ($totalsalary <= 20000) + { + + $esiAmount = $currentDatePF * 1.75 / 100; + /** esiamount not elgiable for 20000 **/ + } + else + { + $esiAmount = 0; + } + $pfAmount = $currentDaySalary * 12 / 100; + /** pf amount per day**/ + + //echo $totalothour;die; + $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances; + $salaryInCurrentday = $salaryInCurrentdays - ($esiAmount + $pfAmount); + $employeeSalary += round($salaryInCurrentday); + + } + // echo $employeeSalary; + } + + } + + + //$salaryInCurrentday++; + + + $data['employeeSalary'] = $employeeSalary; + + + + $working = array(); + $overtime = array(); + //$holid = array(); + for ($i = 1; $i <= $dat; $i++) //echo $dat; die; + { + + + $Working [] = 'WH' . $i; + $overtime [] = 'OT' . $i; + + $CUR_month = date('t'); + // echo $CUR_month; die; + // foreach ($holiday as $value) + // { + // //$holid []= 'WH'.$value; + // if($i==$value) { + // $holid []=$value; + // } + // } + + } + //print_r($WH);die; + $WH = implode(",", $Working); + + + $OT = implode(",", $overtime); + $salarycurrentdate = array(); + + + + $toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $date); + + + $totalSalary = 0; + $working = explode(",", $WH); + $overtime = explode(",", $OT); + foreach ($toDayEmployee as $value) + { + $values = 0; + foreach ($working as $work) + { +// foreach ($overtime as $extra) { + + if ($value[$work] != 0 || $value['OT' . substr($work, 2)] != 0) + { + $totalothour = $value['OT' . substr($work, 2)]; + //echo $totalothour; + $values = 1; + + //print_r($values); die; + $Empid = $value['EmpID']; + //echo $Empid; + + $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); + if(!empty($totalEmployeePersent)) + { + + $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; + $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; + $totalsalary = $totalEmployeePersent[0]->TotalSalary; + $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; + //$allowances =$totalEmployeePersent[0]->Allowances; + + // $Allowances = $allowances * $values; + + + $Food_Allowances = $dayFoodAmt * $values; + + $daySalary = $Basic_Pay / $CUR_month; + /**per day salary working hour**/ + //echo $daySalary.'
'; + + $dayHra = $HRA_Amount / $CUR_month; + /** per day hra amount **/ + //echo $dayHra.'
'; + $onehoursSalary = ($daySalary + $dayHra) / 8; + /**one hour salay ot calculation**/ + if ($totalothour != 0) /** if ot not equal zero **/ + { + $totSalayOT = $totalothour * $onehoursSalary; + } + else + { + $totSalayOT = 0; + } + $currentDaySalary = $daySalary * $values; + /** current day salary working days calculation**/ + + + $currentDayHra = $dayHra * $values; + /** total working days hra calculations**/ + // echo $currentDayHra.'
'; + $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; + /** current date pf calculation**/ + if ($totalsalary <= 20000) + { + + $esiAmount = $currentDatePF * 1.75 / 100; + /** esiamount not elgiable for 20000 **/ + } else { + $esiAmount = 0; + } + $pfAmount = $currentDaySalary * 12 / 100; + /** pf amount per day**/ + + //echo $totalothour;die; + $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances ; + + $salaryInCurrentday = $salaryInCurrentdays -($esiAmount+$pfAmount); + $totalSalarys = $totalSalary + $salaryInCurrentday; + + $totalSalary = round($totalSalarys); +// $salarycurrentdate[] = $salaryInCurrentday;; + // echo 'totalSalary'; + } + + } + + } + } + $data['totalSalary'] = $totalSalary; + // print_r( 'totalSalary');die; + + + $this->loadViews("dashboard", $this->global, $data, NULL); + } + +/*date click on day salary,absent name, total absent display*/ + +function dateFunctionChangeVales() +{ + + + + $date = $this->input->post("id"); + $dates = date('Y-m'); + $date = $dates . '-01'; + // // echo $date; + // $dat = date('d', strtotime("-1 days")); + //echo $date; + + $WH = 'WH' . date('j', strtotime("-1 days")); + + //echo($WH); + $yesterday = $this->dahsboard_Model->attyesterday($WH, $date); + //print_r($yesterday);die; + $values = 0; + foreach ($yesterday as $weekda => $value) + { + + if ($value[$WH] == 0) + { + + $values++; + } + + + } + // echo $values; + $data['values'] = $values; + + + + + $date = $this->input->post("id"); + // echo $date; + $daydate = date('Y-m',strtotime($date)); + //echo $date; die; + $daydate = $daydate . '-01'; + //$dat = date('d'); + // echo $daydate; echo ""; + $WH = 'WH' . date('j',strtotime($date)); + // echo $WH; + + $yesterday = $this->dahsboard_Model->attyesterday($WH, $daydate); + // print_r($yesterday); + + + //$absEmp =array($absEmp); + $values = 0; + $absEmp = array(); + //echo $value; die; + foreach ($yesterday as $weekda => $value) + { + // echo $value[$WH]; + + if ($value[$WH] == 0) + { + + $values++; + $absendId = $value['EmpID']; + $absendName = $value['FirstName']; + $absEmp [] = $absendId . "-" . $absendName; //absend empid and name list + } + } + + //print_r($absentName);die; + $data['today'] = $values; + $data['absname'] = $absEmp; + + $OT = 'OT' . date('j',strtotime($date)); + + $CUR_month = date('t'); + //echo $CUR_month; + //echo $daydate; + $toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $daydate); + //$EmpID = $toDayEmployee[0]->EmpID; + + //print_r($toDayEmployee); die; + + $EmpID = 0; + + $employeeSalary = 0; + + foreach ($toDayEmployee as $value) + { + $values = 0; + $totalothour = 0; + + if ($value[$WH] != 0) + { + + $totalothour = $value[$OT]; + //echo $totalothour;die; + $values = 1; + + //print_r($values); die; + $Empid = $value['EmpID']; + //print_r($value['EmpID']); + + $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); + + // echo $Empid; + // print_r($totalEmployeePersent); + + if(!empty($totalEmployeePersent)) + { + + $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; + $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; + $totalsalary = $totalEmployeePersent[0]->TotalSalary; + $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; + //$allowances =$totalEmployeePersent[0]->Allowances; + //echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary)); + //$Allowances = $allowances * $values; + $Food_Allowances = $dayFoodAmt * $values; + + $daySalary = $Basic_Pay / $CUR_month; + /**per day salary working hour**/ + //echo $daySalary.'
'; + + $dayHra = $HRA_Amount / $CUR_month; + /** per day hra amount **/ + //echo $dayHra.'
'; + + $onehoursSalary = ($daySalary + $dayHra) / 8; + /**one hour salay ot calculation**/ + if ($totalothour != 0) /** if ot not equal zero **/ + { + $totSalayOT = $totalothour * $onehoursSalary; + } else { + $totSalayOT = 0; + } + $currentDaySalary = $daySalary * $values; + /** current day salary working days calculation**/ + + + $currentDayHra = $dayHra * $values; + /** total working days hra calculations**/ + // echo $currentDayHra.'
'; + $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; + /** current date pf calculation**/ + if ($totalsalary <= 20000) + { + + $esiAmount = $currentDatePF * 1.75 / 100; + /** esiamount not elgiable for 20000 **/ + } else { + $esiAmount = 0; + } + $pfAmount = $currentDaySalary * 12 / 100; + /** pf amount per day**/ + + //echo $totalothour;die; + $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances; + $salaryInCurrentday = $salaryInCurrentdays - ($esiAmount + $pfAmount); + $employeeSalary += round($salaryInCurrentday); + + } + // echo $employeeSalary; + } + + } + + + //$salaryInCurrentday++; + + + $data['employeeSalary'] = $employeeSalary; + + $working = array(); + $overtime = array(); + //$holid = array(); + $len = date('d',strtotime($date)); + for ($i = 1; $i <= $len; $i++) //echo $dat; die; + { + + + $Working [] = 'WH' . $i; + $overtime [] = 'OT' . $i; + + $CUR_month = date('t'); + // echo $CUR_month; die; + // foreach ($holiday as $value) + // { + // //$holid []= 'WH'.$value; + // if($i==$value) { + // $holid []=$value; + // } + // } + + } + //print_r($Working);die; + $WH = implode(",", $Working); + + + $OT = implode(",", $overtime); + $salarycurrentdate = array(); + + + + $toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $daydate); + + + $totalSalary = 0; + $working = explode(",", $WH); + $overtime = explode(",", $OT); + foreach ($toDayEmployee as $value) + { + $values = 0; + foreach ($working as $work) + { +// foreach ($overtime as $extra) { + + if ($value[$work] != 0 || $value['OT' . substr($work, 2)] != 0) + { + $totalothour = $value['OT' . substr($work, 2)]; + //echo $totalothour; + $values = 1; + + //print_r($values); die; + $Empid = $value['EmpID']; + //echo $Empid; + + $totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid); + if(!empty($totalEmployeePersent)) + { + + $HRA_Amount = $totalEmployeePersent[0]->HRA_Amount; + $Basic_Pay = $totalEmployeePersent[0]->Basic_Pay; + $totalsalary = $totalEmployeePersent[0]->TotalSalary; + $dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances; + //$allowances =$totalEmployeePersent[0]->Allowances; + + // $Allowances = $allowances * $values; + + + $Food_Allowances = $dayFoodAmt * $values; + + $daySalary = $Basic_Pay / $CUR_month; + /**per day salary working hour**/ + //echo $daySalary.'
'; + + $dayHra = $HRA_Amount / $CUR_month; + /** per day hra amount **/ + //echo $dayHra.'
'; + $onehoursSalary = ($daySalary + $dayHra) / 8; + /**one hour salay ot calculation**/ + if ($totalothour != 0) /** if ot not equal zero **/ + { + $totSalayOT = $totalothour * $onehoursSalary; + } + else + { + $totSalayOT = 0; + } + $currentDaySalary = $daySalary * $values; + /** current day salary working days calculation**/ + + + $currentDayHra = $dayHra * $values; + /** total working days hra calculations**/ + // echo $currentDayHra.'
'; + $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; + /** current date pf calculation**/ + if ($totalsalary <= 20000) + { + + $esiAmount = $currentDatePF * 1.75 / 100; + /** esiamount not elgiable for 20000 **/ + } else { + $esiAmount = 0; + } + $pfAmount = $currentDaySalary * 12 / 100; + /** pf amount per day**/ + + //echo $totalothour;die; + $salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances ; + + $salaryInCurrentday = $salaryInCurrentdays -($esiAmount+$pfAmount); + $totalSalarys = $totalSalary + $salaryInCurrentday; + + $totalSalary = round($totalSalarys); +// $salarycurrentdate[] = $salaryInCurrentday;; + // echo 'totalSalary'; + } + + } + + } + } + $data['totalSalary'] = $totalSalary; + + //print_r($data['totalSalary']);die; + // } + echo json_encode($data); +} + + +/*this function uesd to finance startdate */ + + public function getFinancialStartDate() + { + + + + $CURMONTH = date('n'); + $CURYEAR = date('Y'); + $FINYEAR = 0; + if ($CURMONTH >= 4) + { + $FINYEAR = $CURYEAR; + } else + { + $FINYEAR = $CURYEAR - 1; + } + + $dateInString = $FINYEAR . '-4-1'; + $result = date_create($dateInString); + // print_r($result); + + return $result; + +} + + +/*this function uesd to finance EndDate */ + public function getFinancialEndDate() + { + $CURMONTH = date('n'); + $CURYEAR = date('Y'); + $FINYEAR = 0; + if ($CURMONTH < 4) + { + $FINYEAR = $CURYEAR; + } else + { + $FINYEAR = $CURYEAR + 1; + } + + $dateInString = $FINYEAR . '-3-31'; + $result = date_create($dateInString); + + + // print_r($result); + return $result; + + + } + + + + /*this function used to speedometer month emp performances display*/ + + function monthattendance($empID ='') +{ + + $date = date('Y-m'); + //echo $date; + $dates = $date . '-01'; + $EmpID = ''; + if(empty($empID)){ + $EmpID = $this->input->post('id'); + } + else + { + $EmpID = $empID; + } + // echo $EmpID;die; + $monthabs = $this->dahsboard_Model->attendance($EmpID, $dates); + $persent_month = date('t');//current month of days 31 + $values = array(); + $otvalues = array(); + + $weekdays = array(); + $otHours = array(); + $date = date('j');//current month current date + + + $CURDATE =date('d');//current month current date + + $CUR_month = date('t'); //current month of days 31 + + + $CURYEAR = date('Y'); + $CURMONTH = date('m'); + + $datejoin = $this->dahsboard_Model->joindate($EmpID); + $DateofJoiningInString = $datejoin[0]->DateofJoining; + $DateofJoining = date_create($DateofJoiningInString); + $doj_month = date_format($DateofJoining, "n"); + $doj_year = date_format($DateofJoining, "Y"); + $doj_day = date_format($DateofJoining, "j"); + //echo $doj_day; + for ($i = 1; $i <= $persent_month; $i++) + { + $weekdays[] = 'WH' . $i; + $otHours[] = 'OT' . $i; + } + $totalwhhours=0; + foreach ($monthabs as $weekda) + { + //print_r($weekda); + foreach ($weekda as $key => $value) + { + //print_r($key); + foreach ($weekdays as $weeks) + { + if ($weeks == $key) + { + //print_r($key); + if ($value != 0) + { + //echo $value; + $values[] = $value; + + } + //echo $values; + } + + } + foreach ($otHours as $ot) + { + if ($ot == $key) + { + if ($value != 0) + { + $otvalues [] = $value; + + } + + } + } + + } + } + + + $totalothour = array_sum($otvalues); + //$totalwhhour = sizeof($values); + $totalwhhours = array_sum($values); + + $totalwhhour = $totalwhhours/8; + //echo $totalwhhour; + if ($CURMONTH == $doj_month && $CURYEAR == $doj_year) + { + //echo $doj_day; + $data['CUR_month'] = $CURDATE - $doj_day + 1; + //print_r($month); + } + else + { + $data['CUR_month'] = $date; + } + + if ($totalwhhour != 0) + { + $year = date('Y'); + $current_month = date('m'); + + $data['values'] = $totalwhhour; + //$data['salaryInCurrentday'] = round($salaryInCurrentday); + $data['present_percentage'] = round(($totalwhhour / $data['CUR_month']) * 100); + + } + + else { + + $data['values'] = 0; + //$data['salaryInCurrentday'] = 0; + $data['present_percentage'] = 0; + + } + if(empty($empID)){ + echo json_encode( $data); + } + else{ + return $data; + } + } + + + + + + + + /*this function used to speedometer year emp performances display*/ + +function attendanceyear($empID ='') +{ + + $CURMONTH = date('m'); + $CURDATE = date('d'); + $CURYEAR = date('Y'); + $EmpID = ''; + if(empty($empID)) + { + $EmpID = $this->input->post('id'); + } + else + { + $EmpID = $empID; + } + + $day = array(); + $datejoin = $this->dahsboard_Model->joindate($EmpID); + + $DateofJoiningInString = $datejoin[0]->DateofJoining; + $DateofJoining = date_create($DateofJoiningInString); + // print_r($DateofJoining); + $doj_month = date_format($DateofJoining, "n"); + $doj_year = date_format($DateofJoining, "Y"); + $doj_day = date_format($DateofJoining, "j"); + + $finStart = $this->getFinancialStartDate(); + $finEnd = $this->getFinancialEndDate(); + + $JoinedMonth = date_format($DateofJoining, "n"); + + // print_r($finStart);print_r($finEnd); + //print $JoinedMonth; + + if ($DateofJoining >= $finStart && $DateofJoining <= $finEnd) + { + $JoinedMonthAttendance = $this->dahsboard_Model->getAllAttendances($EmpID,$JoinedMonth); + $joinedMonthDaysCount = cal_days_in_month(CAL_GREGORIAN, $doj_month, $doj_year); + + if ($CURMONTH == $doj_month && $CURYEAR == $doj_year) + { + $joinedMonthWorkingDayCount = $CURDATE - $doj_day +1 ; + } + else + { + $joinedMonthWorkingDayCount = $joinedMonthDaysCount - $doj_day +1; + } + + $joinedMonthDays = 0; + for ($j = $doj_day; $j <= $joinedMonthDaysCount; $j++) + { + $weekdays[] = 'WH' . $j; + } + foreach ($JoinedMonthAttendance as $day) + { + foreach ($day as $key => $value) + { + foreach ($weekdays as $weeks) + { + if ($weeks == $key) + { + if ($value != 0) + { + // echo $value; + $joinedMonthDays++; + } + } + + } + } + + } + + //echo $joinedMonthDays;die; + + $result = $this->dahsboard_Model->attendanceyear($EmpID, $JoinedMonth + 1); + + //print_r($result); + $yearabs = $this->dahsboard_Model->getAllAttendance($EmpID, $CURMONTH); + $TotalNoofDays = $result[0]->TotalWorkingDays; + $DaysWorked = $result[0]->DaysWorked; + + // echo $TotalNoofDays; + // echo $DaysWorked;die; + $values = 0; + $values = array(); + $weekdays = array(); + $date = date('d'); + + $Work = array_sum($weekdays); + + for ($j = 1; $j <= $date; $j++) + { + $weekdays[] = 'WH' . $j; + } + $totalhours =0; + foreach ($yearabs as $day) + { + foreach ($day as $key => $value) + { + foreach ($weekdays as $weeks) + { + if ($weeks == $key) + { + if ($value != 0) + { + //$values++; + //$totalhours = array_sum($value); + $values[] = $value; + + } + } + + } + } + } + + $DaysWorked = 0; + + $totalhours = array_sum($values); + + $values = $totalhours/8; + //print_r($totalhours); + + if ($CURMONTH == $doj_month && $CURYEAR == $doj_year) + { + $TotalNoofDays = $TotalNoofDays + $joinedMonthWorkingDayCount; + $DaysWorked = $joinedMonthDays; + } + else + { + $TotalNoofDays = $TotalNoofDays + $CURDATE + $joinedMonthWorkingDayCount; + $DaysWorked = $DaysWorked + $joinedMonthDays + $values; + } + + + + + $final_res = round(($DaysWorked / $TotalNoofDays) * 100); + // echo "------"; + //echo $final_res;exit(); + $data['workeds'] = $DaysWorked; + $data['yeardata'] = $final_res; + $data['totaldays'] = $TotalNoofDays; + + } + + else + { + $result = $this->dahsboard_Model->attendanceyear($EmpID, 4); + $yearabs = $this->dahsboard_Model->getAllAttendance($EmpID, $CURMONTH); + $TotalNoofDays = $result[0]->TotalWorkingDays; + $DaysWorked = $result[0]->DaysWorked; + + + $values = 0; + $values = array(); + $weekdays = array(); + $date = date('d'); + + $Work = array_sum($weekdays); + + for ($j = 1; $j <= $date; $j++) + { + $weekdays[] = 'WH' . $j; + } + foreach ($yearabs as $day) + { + foreach ($day as $key => $value) + { + foreach ($weekdays as $weeks) + { + if ($weeks == $key) + { + if ($value != 0) + { + + $values[]=$value; + } + } + + } + } + } + + $totalhours = array_sum($values); + + $values = $totalhours/8; + + $TotalNoofDays = $TotalNoofDays + $CURDATE; + $DaysWorked = $DaysWorked + $values; + $final_res = round(($DaysWorked / $TotalNoofDays) * 100); + // echo "------"; + //echo $final_res;exit(); + $data['workeds'] = $DaysWorked; + $data['yeardata'] = $final_res; + $data['totaldays'] = $TotalNoofDays; + + + } + + if(empty($empID)) + { + + echo json_encode($data); + } + else + { + return $data; + } +} + + + + + + + + + + + +/****************HR DASHBOART Controller END **************************************/ + + /** + * This function is used to load the user list + */ + function userListing() + { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { + + $data['userRecords'] = $this->user_model->userListing(); + + $this->global['pageTitle'] = 'Siddharth : User Listing'; + + $this->loadViews("users", $this->global, $data, NULL); + //} + } + + + /** + * This function is used to load the add new form + */ + function addNew() + { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { + $data['EmpList'] = $this->user_model->getAllEmployees(); + + $data['roles'] = $this->user_model->getUserRoles(); + + $data['Department'] = $this->costcenter_model->getDepartment(); + + $this->global['pageTitle'] = 'Siddharth : Add New User'; + + $this->loadViews("addNew", $this->global, $data, NULL); + // } + } + + /** + * This function is used to check whether email already exist or not + */ + function checkEmailExists() + { + $userId = $this->input->post("userId"); + $email = $this->input->post("email"); + + if(empty($userId)){ + $result = $this->user_model->checkEmailExists($email); + } else { + $result = $this->user_model->checkEmailExists($email, $userId); + } + + if(empty($result)){ echo("true"); } + else { echo("false"); } + } + /* Validation for Employee Dropdown + */ + function Employee_validate($selectValue) +{ + //echo 'select_validate method called'; + // 'none' is the first option and the text says something like "-Choose one-" + if($selectValue == '0') + { + $this->form_validation->set_message('Employee_validate', 'Please Select Employee.'); + return false; + } + else // user picked something + { + return true; + } +} + /* Validation for Employee Dropdown + */ + function Role_validate($selectValue) +{ + //echo 'select_validate method called'; + // 'none' is the first option and the text says something like "-Choose one-" + if($selectValue == '0') + { + $this->form_validation->set_message('Role_validate', 'Please Select Role.'); + return false; + } + else // user picked something + { + return true; + } +} + /** + * This function is used to add new user to the system + */ + function addNewUser() + { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { + + $this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS'); + // $this->form_validation->set_rules('role','role','trim|callback_Role_validate'); + $this->form_validation->set_rules('password','Password','required|max_length[20]'); + $this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]'); + + + if($this->form_validation->run() == FALSE) + { + $this->addNew(); + } + else + { + $EmpID = $this->input->post('EmpList'); + $roleId = '2'; + $password = $this->input->post('password'); + $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); + $Createddt = $dt->format('Y-m-d H:i:s'); + + $email = $this->input->post('MailID'); + + $SelectedDepartment = $this->input->post('txtSelectedDepartment'); + + $comma_separated = explode(':', $SelectedDepartment); + + + + + + + $userInfo = array('email'=>$email,'EmpID'=>$EmpID,'password'=>getHashedPassword($password),'roleId'=>$roleId,'createdBy'=>$this->vendorId,'createdDtm'=>$Createddt); + + + + //die(); + + $result = $this->user_model->addNewUser($userInfo); + + if($SelectedDepartment != '') + { + + for ($j = 0; $j < count($comma_separated); $j++) + { + $DeptCode = $comma_separated[$j]; + + //echo $DeptCode; + + $userdept=array('EmpID'=>$EmpID,'Departmentcode'=>$DeptCode); + + //print_r($userdept); + + $access= $this->user_model->addAccess($userdept); + + //echo $access; + } + } + + + if($result > 0) + { + + + echo ""; + redirect('userListing','refresh'); + + } + + else + { + + redirect('userListing','refresh'); + echo ""; + } + + } + //} + } + + + + + +function Adduserdepartment() + { + $empid= $this->input->post('Eid'); + $Depcode= $this->input->post('Department'); + $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); + + $access= $this->user_model->addAccess($userdept); + if($access>0) + { + echo "Successfully Added"; + } + } + + + function Deleteuserdepartment() + { + $empid= $this->input->post('Eid'); + $Depcode= $this->input->post('Department'); + $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); + + $access= $this->user_model->DeleteAccess($empid,$Depcode); + + if($access>0) + { + echo "Successfully Deleted"; + } + + } + + + /** + * This function is used load user edit information + * @param number $userId : Optional : This is user id + */ + function editOld($UserId = '') + { + // if($this->isAdmin() == TRUE ) + // { + // $this->loadThis(); + // } + // else + // { + if($UserId == '') + { + // redirect('userListing'); + } + + $Uid = $_GET['UID']; + $Empid = $_GET['EMPID']; + + + $data['roles'] = $this->user_model->getUserRoles(); + + //print_r($data); + + $data['EmpList'] = $this->user_model->GetEmployeeDetails($Uid); + //print_r($data); + $data['Departmentlist'] = $this->costcenter_model->getDepartmentnotadded($Empid); + $data['EmpRole'] = $this->user_model->GetRoleNameByUserID($Uid); + $data['AccessDept'] = $this->costcenter_model ->getaccessDept($Empid); + + // $data['userInfo'] = $this->user_model->getUserInfo($userId); + + $this->global['pageTitle'] = 'Siddharth : Edit User'; + + $this->loadViews("editOld", $this->global, $data, NULL); + //} + } + + + /** + * This function is used to edit the user information + */ + function editUser() + { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { + $userId = $this->input->post('EmpList'); + $this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS'); + $this->form_validation->set_rules('role','role','trim|callback_Role_validate'); + $this->form_validation->set_rules('password','Password','required|max_length[20]'); + $this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]'); + + if($this->form_validation->run() == FALSE) + { + $this->editOld($userId); + } + else + { + $EmpID = $this->input->post('EmpList'); + $role = $this->input->post('role'); + $password = $this->input->post('password'); + $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); + $updatedDate = $dt->format('Y-m-d H:i:s'); + + // echo $EmpID; + + $userInfo = array(); + + + $userInfo = array('password'=>getHashedPassword($password),'roleId'=>$role,'EmpId'=>$EmpID,'updatedDtm'=>$updatedDate); + + + + + $result = $this->user_model->editUser($userInfo, $EmpID); + + if($result == true) + { + $this->session->set_flashdata('success', 'User updated successfully'); + } + else + { + $this->session->set_flashdata('error', 'User updation failed'); + } + + redirect('userListing'); + } + //} + } + + + /** + * This function is used to delete the user using userId + * @return boolean $result : TRUE / FALSE + */ + function deleteUser() + { + echo 'Delete'; + $Uid = $this->input->post('id'); + + $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); + $updatedDate = $dt->format('Y-m-d H:i:s'); + + $userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>$updatedDate); + + $result = $this->user_model->deleteUser($Uid, $userInfo); + + echo 'Succssfully change the user status to InAcive'; + + } + + /** + * This function is used to load the change password screen + */ + function loadChangePass() + { + $this->global['pageTitle'] = 'Siddharth : Change Password'; + + $this->loadViews("changePassword", $this->global, NULL, NULL); + } + + + /** + * This function is used to change the password of the user + */ + function changePassword() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('oldPassword','Old password','required|max_length[20]'); + $this->form_validation->set_rules('newPassword','New password','required|max_length[20]'); + $this->form_validation->set_rules('cNewPassword','Confirm new password','required|matches[newPassword]|max_length[20]'); + + if($this->form_validation->run() == FALSE) + { + $this->loadChangePass(); + } + else + { + $oldPassword = $this->input->post('oldPassword'); + $newPassword = $this->input->post('newPassword'); + + $resultPas = $this->user_model->matchOldPassword($this->vendorId, $oldPassword); + + if(empty($resultPas)) + { + $this->session->set_flashdata('nomatch', 'Your old password not correct'); + redirect('loadChangePass'); + } + else + { + $usersData = array('password'=>getHashedPassword($newPassword), 'updatedBy'=>$this->vendorId, + 'updatedDtm'=>date('Y-m-d H:i:sa')); + + $result = $this->user_model->changePassword($this->vendorId, $usersData); + + if($result > 0) { $this->session->set_flashdata('success', 'Password updation successful'); } + else { $this->session->set_flashdata('error', 'Password updation failed'); } + + redirect('loadChangePass'); + } + } + } + + function pageNotFound() + { + $this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found'; + + $this->loadViews("404", $this->global, NULL, NULL); + } + //this function used to delivery performances + +function deliver_perform() +{ + + + $this->global['pageTitle'] = 'Siddharth : Delivery Performance'; + if ($this->input->post('btn_submit')) { + + $ab=$this->input->post('financialyear'); + + $fa=substr($ab,0,-5); + $aa=substr($ab,5,5); + $m=$this->input->post('month'); + + //print_r($prod); + //die; + + $data['fy']=$this->user_model->fincalYear(); + $data['per']=$this->user_model->deliver_perform($fa,$aa,$m); + + // // print_r( $data['spurchse']); + } + + $data['fy']=$this->user_model->fincalYear(); + + $this->loadviews("deliver_perform",$this->global,$data,NULL); + + +} + /* + *favourite add function and load view + */ + + function favourite() + { + $this->global['pageTitle'] = 'Siddharth :Favourite '; + + + // $data['ponoreset']=$this->purchaseorder_model->ponoresetfinyear(); + + + $this->loadViews("Favourite", $this->global,Null); + + } + function favouriteadd() + { + $name = $this->input->post('name'); + $url = $this->input->post('url'); + $status = $this->input->post('status'); + $CreateBy = $this->session->userdata ( 'userId' ); + + $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); + $createddt = $dt->format('Y-m-d H:i:s'); + $menu = $this->input->post('menu'); + // $RowCount = $this->input->post('txtRowCount'); + // $DeletedRow = $this->input->post('txtDeletedRow'); + // $comma_separated = explode(':', $DeletedRow); + $favourite = array('Menu_Name'=>$name,'Menu_URL'=>$url,'Status'=>$status,'Created_BY'=>$CreateBy,'Created_ON'=>$createddt,'Menu_ID'=>$menu); + $getdata= $this->user_model->favouriteadd($favourite); + // print_r($favourite); + // die(); + if($getdata==1) + + { + echo"success"; + + } + else{ + echo"failed"; + } + + } +} + +?> diff --git a/application/helpers/cias_helper.php b/application/helpers/cias_helper.php index b1002c35..98b830bb 100644 --- a/application/helpers/cias_helper.php +++ b/application/helpers/cias_helper.php @@ -131,10 +131,10 @@ where (CurrentStock+OpeningStock)db->query($subQuery,array()); + $query=$CI->db->query($subQuery,array()); //print_r($this->db->last_query()); - return array(); + return $query->result(); } ?> \ No newline at end of file diff --git a/application/helpers/zohobooks_fetch_api_helper.php b/application/helpers/zohobooks_fetch_api_helper.php index dec15360..b43e125b 100644 --- a/application/helpers/zohobooks_fetch_api_helper.php +++ b/application/helpers/zohobooks_fetch_api_helper.php @@ -1,73 +1,73 @@ -access_token; -} - - -function getheringInvoiceDetails($date_today , $date_yesterday , $accesstoken) -{ - $ch=curl_init(); - $organization_id = '655654572'; - $url_org ="https://books.zoho.com/api/v3/invoices?"; - $fields=array("usestate" => "true","organization_id" => $organization_id,"date_start" => $date_yesterday,"date_end" => $date_today); - $data_all = http_build_query($fields); - $headers=array('Authorization:Zoho-oauthtoken '.$accesstoken,'Content-Type:application/json'); - $data_access = $url_org.$data_all; - curl_setopt($ch, CURLOPT_URL, $url_org.$data_access); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_HEADER, 0); - $body = '{}'; - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); - curl_setopt($ch, CURLOPT_POSTFIELDS,$body); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $result=curl_exec($ch); - $data['headers_new'] = $headers; - $data['data'] = curl_exec($ch); - return $data; -} - - -function getheringInvoiceSubDetails($invoice_id , $organization_id , $headers) -{ - $ch=curl_init(); - $url2 = 'https://books.zoho.com/api/v3/invoices/'.$invoice_id.'?organization_id='.$organization_id; - curl_setopt($ch, CURLOPT_URL, $url2); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_HEADER, 0); - $body2 = '{}'; - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); - curl_setopt($ch, CURLOPT_POSTFIELDS,$body2); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - return curl_exec($ch); -} - +access_token; +} + + +function getheringInvoiceDetails($date_today , $date_yesterday , $accesstoken) +{ + $ch=curl_init(); + $organization_id = '655654572'; + $url_org ="https://books.zoho.com/api/v3/invoices?"; + $fields=array("usestate" => "true","organization_id" => $organization_id,"date_start" => $date_yesterday,"date_end" => $date_today); + $data_all = http_build_query($fields); + $headers=array('Authorization:Zoho-oauthtoken '.$accesstoken,'Content-Type:application/json'); + $data_access = $url_org.$data_all; + curl_setopt($ch, CURLOPT_URL, $url_org.$data_access); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_HEADER, 0); + $body = '{}'; + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($ch, CURLOPT_POSTFIELDS,$body); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result=curl_exec($ch); + $data['headers_new'] = $headers; + $data['data'] = curl_exec($ch); + return $data; +} + + +function getheringInvoiceSubDetails($invoice_id , $organization_id , $headers) +{ + $ch=curl_init(); + $url2 = 'https://books.zoho.com/api/v3/invoices/'.$invoice_id.'?organization_id='.$organization_id; + curl_setopt($ch, CURLOPT_URL, $url2); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_HEADER, 0); + $body2 = '{}'; + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($ch, CURLOPT_POSTFIELDS,$body2); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + return curl_exec($ch); +} + diff --git a/application/libraries/BaseController.php b/application/libraries/BaseController.php index f592a25f..d01bee64 100644 --- a/application/libraries/BaseController.php +++ b/application/libraries/BaseController.php @@ -1,176 +1,176 @@ -output->set_status_header ( 200 )->set_content_type ( 'application/json', 'utf-8' )->set_output ( json_encode ( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) )->_display (); - exit (); - } - - /** - * This function used to check the user is logged in or not - */ - function isLoggedIn() { - $isLoggedIn = $this->session->userdata ( 'isLoggedIn' ); - - if (! isset ( $isLoggedIn ) || $isLoggedIn != TRUE) { - $this->load->library('uri'); - if ($this->uri->segment(2) == 'zohobooks_api_fetch_all') { - redirect('login/zohobooks_api_fetch_all'); - } - redirect ( 'login' ); - } else { - $this->role = $this->session->userdata ( 'role' ); - // print_r($this->role);die(); - // session_start(); - log_message('ERROR','#####In BaseController - isLoggedIn function ci session : ' . $this->session->userdata ( 'name' )); - // log_message('ERR?OR','#####In BaseController - isLoggedIn function session super global methid : ' . $_SESSION['name']); - $this->vendorId = $this->session->userdata ( 'userId' ); - $this->name = $this->session->userdata ( 'name' ); - $this->roleText = $this->session->userdata ( 'roleText' ); - //$this->Designation = $this->session->userdata ( 'Designation' ); - $this->DEPCode = $this->session->userdata ( 'DEPCode' ); - $this->HeadDept = $this->session->userdata ( 'HeadDept' ); - $this->DepartmentName = $this->session->userdata ( 'DepartmentName' ); - $this->EmpID = $this->session->userdata ( 'EmpID' ); - $this->depaccess = $this->session->userdata ('depaccess'); - $this->global ['name'] = $this->name; - $this->global ['role'] = $this->role; - $this->global ['role_text'] = $this->roleText; - $this->global ['DEPCode'] = $this->DEPCode; - $this->global ['Designation'] = $this->Designation; - $this->global ['DepAccesslist'] = $this->depaccess; - } - } - - /** - * This function is used to check the access - */ - function isAdmin() { - if ($this->role != ROLE_ADMIN) { - return true; - } else { - return false; - } - } - - /** - * This function is used to check the access - */ - function isTicketter() { - if ($this->role != ROLE_ADMIN || $this->role != ROLE_MANAGER) { - return true; - } else { - return false; - } - } - - /** - * This function is used to load the set of views - */ - function loadThis() { - $this->global ['pageTitle'] = 'CodeInsect : Access Denied'; - - $this->load->view ( 'includes/header', $this->global ); - $this->load->view ( 'access' ); - $this->load->view ( 'includes/footer' ); - } - - /** - * This function is used to logged out user from system - */ - function logout() { - ob_start(); - $this->load->driver('cache'); - $this->session->set_userdata(); - delete_cookie('ci_session'); - //$this->session->userdata = array('test' => 'tst'); - $this->session->sess_destroy(); - $this->cache->clean(); - ob_clean(); - redirect ( 'login' ); - } - - /** - * This function used to load views - * @param {string} $viewName : This is view name - * @param {mixed} $headerInfo : This is array of header information - * @param {mixed} $pageInfo : This is array of page information - * @param {mixed} $footerInfo : This is array of footer information - * @return {null} $result : null - */ - function loadViews($viewName = "", $headerInfo = NULL, $pageInfo = NULL, $footerInfo = NULL){ - - $this->load->view('includes/header', $headerInfo); - $this->load->view($viewName, $pageInfo); - $this->load->view('includes/footer', $footerInfo); - } - - /** - * This function used provide the pagination resources - * @param {string} $link : This is page link - * @param {number} $count : This is page count - * @param {number} $perPage : This is records per page limit - * @return {mixed} $result : This is array of records and pagination data - */ - function paginationCompress($link, $count, $perPage = 10) { - $this->load->library ( 'pagination' ); - - $config ['base_url'] = base_url () . $link; - $config ['total_rows'] = $count; - $config ['uri_segment'] = SEGMENT; - $config ['per_page'] = $perPage; - $config ['num_links'] = 5; - $config ['full_tag_open'] = ''; - $config ['first_tag_open'] = '
  • '; - $config ['first_link'] = 'First'; - $config ['first_tag_close'] = '
  • '; - $config ['prev_link'] = 'Previous'; - $config ['prev_tag_open'] = '
  • '; - $config ['prev_tag_close'] = '
  • '; - $config ['next_link'] = 'Next'; - $config ['next_tag_open'] = '
  • '; - $config ['next_tag_close'] = '
  • '; - $config ['cur_tag_open'] = '
  • '; - $config ['cur_tag_close'] = '
  • '; - $config ['num_tag_open'] = '
  • '; - $config ['num_tag_close'] = '
  • '; - $config ['last_tag_open'] = '
  • '; - $config ['last_link'] = 'Last'; - $config ['last_tag_close'] = '
  • '; - - $this->pagination->initialize ( $config ); - $page = $config ['per_page']; - $segment = $this->uri->segment ( SEGMENT ); - - return array ( - "page" => $page, - "segment" => $segment - ); - } -} +output->set_status_header ( 200 )->set_content_type ( 'application/json', 'utf-8' )->set_output ( json_encode ( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) )->_display (); + exit (); + } + + /** + * This function used to check the user is logged in or not + */ + function isLoggedIn() { + $isLoggedIn = $this->session->userdata ( 'isLoggedIn' ); + + if (! isset ( $isLoggedIn ) || $isLoggedIn != TRUE) { + $this->load->library('uri'); + if ($this->uri->segment(2) == 'zohobooks_api_fetch_all') { + redirect('login/zohobooks_api_fetch_all'); + } + redirect ( 'login' ); + } else { + $this->role = $this->session->userdata ( 'role' ); + // print_r($this->role);die(); + // session_start(); + log_message('ERROR','#####In BaseController - isLoggedIn function ci session : ' . $this->session->userdata ( 'name' )); + // log_message('ERR?OR','#####In BaseController - isLoggedIn function session super global methid : ' . $_SESSION['name']); + $this->vendorId = $this->session->userdata ( 'userId' ); + $this->name = $this->session->userdata ( 'name' ); + $this->roleText = $this->session->userdata ( 'roleText' ); + //$this->Designation = $this->session->userdata ( 'Designation' ); + $this->DEPCode = $this->session->userdata ( 'DEPCode' ); + $this->HeadDept = $this->session->userdata ( 'HeadDept' ); + $this->DepartmentName = $this->session->userdata ( 'DepartmentName' ); + $this->EmpID = $this->session->userdata ( 'EmpID' ); + $this->depaccess = $this->session->userdata ('depaccess'); + $this->global ['name'] = $this->name; + $this->global ['role'] = $this->role; + $this->global ['role_text'] = $this->roleText; + $this->global ['DEPCode'] = $this->DEPCode; + $this->global ['Designation'] = $this->Designation; + $this->global ['DepAccesslist'] = $this->depaccess; + } + } + + /** + * This function is used to check the access + */ + function isAdmin() { + if ($this->role != ROLE_ADMIN) { + return true; + } else { + return false; + } + } + + /** + * This function is used to check the access + */ + function isTicketter() { + if ($this->role != ROLE_ADMIN || $this->role != ROLE_MANAGER) { + return true; + } else { + return false; + } + } + + /** + * This function is used to load the set of views + */ + function loadThis() { + $this->global ['pageTitle'] = 'CodeInsect : Access Denied'; + + $this->load->view ( 'includes/header', $this->global ); + $this->load->view ( 'access' ); + $this->load->view ( 'includes/footer' ); + } + + /** + * This function is used to logged out user from system + */ + function logout() { + ob_start(); + $this->load->driver('cache'); + $this->session->set_userdata(); + delete_cookie('ci_session'); + //$this->session->userdata = array('test' => 'tst'); + $this->session->sess_destroy(); + $this->cache->clean(); + ob_clean(); + redirect ( 'login' ); + } + + /** + * This function used to load views + * @param {string} $viewName : This is view name + * @param {mixed} $headerInfo : This is array of header information + * @param {mixed} $pageInfo : This is array of page information + * @param {mixed} $footerInfo : This is array of footer information + * @return {null} $result : null + */ + function loadViews($viewName = "", $headerInfo = NULL, $pageInfo = NULL, $footerInfo = NULL){ + + $this->load->view('includes/header', $headerInfo); + $this->load->view($viewName, $pageInfo); + $this->load->view('includes/footer', $footerInfo); + } + + /** + * This function used provide the pagination resources + * @param {string} $link : This is page link + * @param {number} $count : This is page count + * @param {number} $perPage : This is records per page limit + * @return {mixed} $result : This is array of records and pagination data + */ + function paginationCompress($link, $count, $perPage = 10) { + $this->load->library ( 'pagination' ); + + $config ['base_url'] = base_url () . $link; + $config ['total_rows'] = $count; + $config ['uri_segment'] = SEGMENT; + $config ['per_page'] = $perPage; + $config ['num_links'] = 5; + $config ['full_tag_open'] = ''; + $config ['first_tag_open'] = '
  • '; + $config ['first_link'] = 'First'; + $config ['first_tag_close'] = '
  • '; + $config ['prev_link'] = 'Previous'; + $config ['prev_tag_open'] = '
  • '; + $config ['prev_tag_close'] = '
  • '; + $config ['next_link'] = 'Next'; + $config ['next_tag_open'] = '
  • '; + $config ['next_tag_close'] = '
  • '; + $config ['cur_tag_open'] = '
  • '; + $config ['cur_tag_close'] = '
  • '; + $config ['num_tag_open'] = '
  • '; + $config ['num_tag_close'] = '
  • '; + $config ['last_tag_open'] = '
  • '; + $config ['last_link'] = 'Last'; + $config ['last_tag_close'] = '
  • '; + + $this->pagination->initialize ( $config ); + $page = $config ['per_page']; + $segment = $this->uri->segment ( SEGMENT ); + + return array ( + "page" => $page, + "segment" => $segment + ); + } +} diff --git a/application/models/batchcard_model.php b/application/models/batchcard_model.php index b425002e..836f485a 100644 --- a/application/models/batchcard_model.php +++ b/application/models/batchcard_model.php @@ -1,1689 +1,1689 @@ -db->select('T_Employee_Details.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Employee_Details.Departmentcode,T_DepartmentDetails.shortName'); - $this->db->from('T_Employee_Details'); - $this->db->join('T_DepartmentDetails','T_Employee_Details.Departmentcode=T_DepartmentDetails.DEPCode'); - //$this->db->join('ip_invoice_items','ip_invoices.invoice_number=ip_invoice_items.invoice_number'); - //$this->db->join('ip_products','ip_invoice_items.item_product_id=ip_products.product_id'); - //$this->db->join('ip_invoice_custom','ip_invoices.invoice_number=ip_invoice_custom.invoice_number and invoice_custom_fieldid=62'); - $this->db->order_by('T_Employee_Details.EmpID'); - $res = $this->db->get(); - return $res->result(); - - } - - function getSupplierlist(){ - - $this->db->select('SupplierName,SupplierID'); - $this->db->from('T_SupplierDetailsN'); - $supp = $this->db->get(); - return $supp->result(); - - } - - - - function Rawsupplier() - { - - $this->db->select('mas.SupplierID,sup.SupplierName,mmas.MaterialCode,mmas.MaterialName'); - $this->db->from('T_PurchaseOrder_Master mas'); - $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); - $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); - $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); - $this->db->where('Category','Raw Material'); - $this->db->group_by('SupplierID'); - $supp = $this->db->get(); - - - // print_r($this->db->last_query());die(); - return $supp->result(); - - - } - - - - function Consupplier() - { - $this->db->select('mas.SupplierID,sup.SupplierName'); - $this->db->from('T_PurchaseOrder_Master mas'); - $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); - $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); - $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); - $this->db->where('Category','Consumables'); - $this->db->group_by('SupplierID'); - $supp = $this->db->get(); - return $supp->result(); - } - - - - function Pacsupplier() - { - $this->db->select('mas.SupplierID,sup.SupplierName'); - $this->db->from('T_PurchaseOrder_Master mas'); - $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); - $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); - $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); - $this->db->where('Category','Packing material'); - $this->db->group_by('SupplierID'); - $supp = $this->db->get(); - return $supp->result(); - - } - - - function getStockValue() - { - $this->db->select('MaterialCode,stock,stockdate'); - $this->db->from('T_MaterialMaster'); - $supp = $this->db->get(); - return $supp->result(); - } - - function saveHourlyBatchInfo($datatostore) - { - $this->db->insert('T_hourly_batch_info',$datatostore); - $res = $this->db->affected_rows(); - - return $res; - } - - function saveDailyBatchCardData($datatostore) - { - $this->db->insert('T_daily_batchcard_data',$datatostore); - $res = $this->db->affected_rows(); - return $res; - } - - function updateHourlyBatchInfo($datatostore,$hid) - { - $this->db->where('hourlyid',$hid); - $this->db->update('T_hourly_batch_info',$datatostore); - $res = $this->db->affected_rows(); - - return $res; - } - - function getAllHourlyData($hid='',$from='',$to='') - { - //echo "Model".$from.'-'.$to; - - $this->db->select('T_hourly_batch_info.*,T_Employee_Details.FirstName as F,T_Employee_Details.LastName as L'); - $this->db->from('T_hourly_batch_info'); - $this->db->join('tbl_users','T_hourly_batch_info.checkedby=tbl_users.userId'); - $this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID'); - if(!empty($hid)) - { - $this->db->where('hourlyid',$hid); - } - if(!empty($from) && !empty($to)) - { - $this->db->where('T_hourly_batch_info.report_date <=',$to); - $this->db->where('T_hourly_batch_info.report_date >=',$from); - } - $this->db->order_by('hourlyid','desc'); - $res = $this->db->get(); - //print_r($res->result());die(); - return $res->result(); - } - - - function checkExistHourlyData($bdate,$btime) - { - //echo 'Model'.$bdate.'-'.$btime; - $this->db->select('count(*) as count'); - $this->db->from('T_hourly_batch_info'); - $this->db->where('report_date',$bdate); - $this->db->where('report_time',$btime); - $res = $this->db->get(); - return $res->result(); - } - - - function getPowerConsumptionDetails($rdate) - { - - $this->db->select('hourlyid,report_time,opening_trp_reading,close_trp_reading,auto_start,auto_stop'); - $this->db->from('T_hourly_batch_info'); - $this->db->where('report_date',$rdate); - $res = $this->db->get(); - return $res->result(); - } - - function getDailyBatchCardData($month) - { - // $this->db->select('*'); - // $this->db->from('T_daily_batchcard_data'); - // $this->db->where('month(ddate)',$month); - $sql = 'select T_daily_batchcard_data.*,T_Employee_Details.FirstName,T_Employee_Details.LastName from T_daily_batchcard_data - join tbl_users on T_daily_batchcard_data.createdby = tbl_users.userId - join T_Employee_Details on T_Employee_Details.EmpID = tbl_users.EmpID - where month(ddate) = ?'; - $res = $this->db->query($sql,array($month)); - return $res->result(); - } - - function getIndividualDailyData($did) - { - - $this->db->select('*'); - $this->db->from('T_daily_batchcard_data'); - $this->db->where('dailyid',$did); - $res = $this->db->get(); - return $res->result(); - - } - - function checkExistDaily($rdate) - { - $this->db->select('count(*) as count'); - $this->db->from('T_daily_batchcard_data'); - $this->db->where('ddate',$rdate); - $res = $this->db->get(); - return $res->result(); - } - - function updateDailyBatchCardData($datatostore,$did) - { - $this->db->where('dailyid',$did); - $this->db->update('T_daily_batchcard_data',$datatostore); - $res = $this->db->affected_rows(); - - return $res; - } - - function checkAbstractReport($date) - { - $this->db->select('count(*) as count'); - $this->db->from('T_abstract_report'); - //$this->db->where('abstract_report_date',$date); - $this->db->where("date_format(abstract_report_date,'%Y-%m')",$date); - $res = $this->db->get(); - return $res->result(); - } - - function saveAbstractReport($datatostore) - { - $this->db->insert('T_abstract_report',$datatostore); - $res = $this->db->affected_rows(); - return $res; - } - - function updateAbstractReport($datatostore,$date,$abstract_details) - { - //$this->db->where('abstract_report_date',$date); - $this->db->where("date_format(abstract_report_date,'%Y-%m')",$date); - $this->db->where('abstract_details',$abstract_details); - $this->db->update('T_abstract_report',$datatostore); - $res = $this->db->affected_rows(); - - return $res; - - } - - function getPreviousMonthAbstractDetails($month,$year) - { - //$sql = "select abstract_details,close_stock from T_abstract_report where month(abstract_report_date) =? and year(abstract_report_date) =? "; - $sql = "select abstract_details,close_stock as Available from T_abstract_report where month(abstract_report_date) =? and year(abstract_report_date) =? "; - $res = $this->db->query($sql,array($month,$year)); - return $res->result(); - - } - - function getMonthAbstractDetails($month_year) - { - $sql = "select abstract_details,close_stock,open_stock as Available,physical_stock from T_abstract_report where date_format(abstract_report_date,'%Y-%m') = ? "; - $res = $this->db->query($sql,array($month_year)); - - return $res->result(); - } - - function getPreviousMonthClosedStockDetails($y,$m,$sn) - { - $month = 'month(ddate)'; - $year = 'year(ddate)'; - //$this->db->select($sn); - $this->db->select($sn,'ddate'); - $this->db->from('T_daily_batchcard_data'); - $this->db->where($month,$m); - $this->db->where($year,$y); - $this->db->order_by('ddate','desc'); - $this->db->limit(1); - $res = $this->db->get(); - //print_r($res->result()); - return $res->result(); - } - - function currentMonthStockDetails($m,$y,$sd1,$sd2) - { - $month = 'month(ddate)'; - $year = 'year(ddate)'; - $list = array('ddate',$sd1,$sd2); - $this->db->select($list); - $this->db->from('T_daily_batchcard_data'); - $this->db->where($month,$m); - $this->db->where($year,$y); - $this->db->order_by('ddate','asc'); - $res = $this->db->get(); - //print_r($res->result()); - return $res->result(); - } - - function addmaint_dtl($array) - { - // $this->db->insert('T_Batchcard_MaintanceDetails',$array); - // $bmd = $this->db->affected_rows(); - // return $bmd; - - $this->db->insert('T_Batchcard_MaintanceDetails',$array); - $bmd = $this->db->affected_rows(); - - - if($bmd>0) - { - $this->db->select('max(Maint_ID) as Maint_ID'); - $this->db->from('T_Batchcard_MaintanceDetails'); - $res = $this->db->get(); - return $res->result(); - } - } - function getmaint_dtl($fdate,$tdate,$type ) - { - - - $this->db->select('BMD.*'); - // $this->db->select() - $this->db->select('CONCAT(ED1.FirstName, " - " , ED1.LastName) AS Approver_Name', FALSE); - $this->db->select('CONCAT(ED2.FirstName, " - " , ED2.LastName) AS Worker_Name', FALSE); - $this->db->from('T_Batchcard_MaintanceDetails BMD'); - - $this->db->join('T_Employee_Details ED1', 'ED1.EmpID = BMD.Approved_By', 'left'); - $this->db->join('T_Employee_Details ED2', 'ED2.EmpID = BMD.WorkDone_By', 'left'); - - - - if ($fdate and $tdate != ''){ - - - $fromdate= date("Y-m-d",strtotime($fdate)); - $todate=date("Y-m-d",strtotime($tdate)); - - $date = "date(BMD.CreatedOn) >= '".$fromdate."' - and date( BMD.CreatedOn) <= '". $todate."'"; - $this->db->where($date); - } - - if($type!=""){ - - $this->db->where("BMD.type" ,$type); - - - } - $bmd = $this->db->get(); - return $bmd->result(); - } - - - - function getmaint_dtl_MntID($MntID) - { - - $this->db->select('*'); - $this->db->from('T_Batchcard_MaintanceDetails'); - $this->db->where('Maint_ID',$MntID); - $bmd = $this->db->get(); - return $bmd->result(); - } - - function updatemaint_dtl($array,$MntID) - { - $this->db->where('Maint_ID',$MntID); - $this->db->update('T_Batchcard_MaintanceDetails',$array); - $bmd = $this->db->affected_rows(); - - return $bmd; - } - - function maintenancesdata($date){ - - $this->db->select("bm.*,mm.Machine_Name"); - $this->db->select("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y') AS date", FALSE); - $this->db->select("DATE_FORMAT(bm.CreatedOn,'%l:%i %p') AS time", FALSE); - $this->db->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE); - $this->db->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE); - $this->db->from("T_Batchcard_MaintanceDetails bm"); - $this->db->join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left"); - $this->db->join("T_Employee_Details ED1", "bm.Approved_By = ED1.EmpID", "left"); - $this->db->join("T_Employee_Details ED2", "bm.WorkDone_By = ED2.EmpID", "left"); - $this->db->where("mm.Machines_Category = 'TRP'"); - //AND DATE_FORMAT(bm.CreatedOn,'%Y-%m-%d') = '19-04-2018' - $this->db->where("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y')",$date); - $bmd = $this->db->get(); - return $bmd->result(); - - //print_r($this->db->last_query()); - //die(); - - } - - function getmachine_codename(){ - $this->db->select('Machine_Code,Machine_Name'); - $this->db->from('T_Machine_Master'); - $res = $this->db->get(); - return $res->result(); - } - - /** Machines History/Master */ - function getdept_dtls() - { - $this->db->select('T_DepartmentDetails.DEPCode,T_DepartmentDetails.shortName'); - $this->db->from('T_DepartmentDetails'); - $this->db->where('IsActive',1); - $res = $this->db->get(); - return $res->result(); - } - - function getpono(){ - - $this->db->select('PONO'); - $this->db->from('T_PurchaseOrder_Master'); - $this->db->where('Status','ST026'); - $res = $this->db->get(); - return $res->result(); - } - - function getpo_dtls($pono){ - - // $this->db->select('T_PurchaseOrder_Master.PONO,T_PurchaseOrder_Master.SupplierID,T_SupplierDetailsN.SupplierName,DATE_FORMAT(T_PurchaseOrder_Master.PODate,"%d-%m-%Y") as PO_Date'); - // $this->db->from('T_PurchaseOrder_Master'); - // $this->db->join('T_SupplierDetailsN','T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID'); - // $this->db->where('PONO',$pono); - // $res = $this->db->get(); - // return $res->result(); - $sql = "select T_PurchaseOrder_Master.PONO,T_PurchaseOrder_Master.SupplierID,T_SupplierDetailsN.SupplierName,DATE_FORMAT(T_PurchaseOrder_Master.PODate,'%d-%m-%Y') as PO_Date - from T_PurchaseOrder_Master - join T_SupplierDetailsN on T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID - where PONO = ? "; - $res = $this->db->query($sql,array($pono)); - return $res->result(); - - } - - function addhist_mstr($array) - { - $this->db->insert('T_Machine_Master',$array); - $mstr = $this->db->affected_rows(); - //print_r($this->db->last_query()); - //print_r($mstr); - if($mstr>0) - { - - $this->db->select('Machine_Code'); - $this->db->from('T_Machine_Master'); - $this->db->order_by('CreatedOn','desc'); - $this->db->limit(1); - $res = $this->db->get(); - //print_r($res->result()); - return $res->result(); - - - - - - } - - } - function addhist_dtl($array){ - - $this->db->insert('T_Machine_Details',$array); - $child = $this->db->affected_rows(); - return $child; - - } - //This function for multi file upload option (both machine and maint/br screen) - function addfiledetails($array){ - - $this->db->insert('T_Machines_file', $array); - $r = $this->db->affected_rows(); - return $r; - //return TRUE; - - } - function insertvalueintoconfig($config){ - - $this->db->insert('T_ConfigDetails', $config); - return TRUE; - } - - //This function used to get the material category using configdetails table - function getmachineCategory($MaterialCategory = '') - { - $Config_ID = 'C028'; - $this->db->select('Config_ID,ConfigValue'); - $this->db->from('T_ConfigDetails'); - $this->db->where('Config_id',$Config_ID ); - if($MaterialCategory != '') - { - $this->db->where('ConfigValue !=',$MaterialCategory ); - } - $query = $this->db->get(); - - return $query->result(); - } - - - function getHist_dtls($MachineCode = '') - { - - $this->db->select('*'); - $this->db->from('T_Machine_Details'); - if($MachineCode != '') - { - $this->db->where('Machine_Code',$MachineCode ); - } - $bmd = $this->db->get(); - return $bmd->result(); - } - - //This function for multi file upload option (both machine and maint/br screen) - function getfiledetails($data = '') - { - - $this->db->select('*'); - $this->db->from('T_Machines_file'); - if($data != '') - { - $this->db->where('Machine_code/Maint_id',$data ); - } - $bmd = $this->db->get(); - return $bmd->result(); - } - - function getHist_mstr($MachineCode = '') - { - - $this->db->select('*'); - $this->db->from('T_Machine_Master'); - if($MachineCode != '') - { - $this->db->where('Machine_Code',$MachineCode ); - } - $bmd = $this->db->get(); - return $bmd->result(); - } - - // function getHist_dtlsID($MntID) - // { - - // $this->db->select('*'); - // $this->db->from('T_Batchcard_MaintanceDetails'); - // $this->db->where('Maint_ID',$MntID); - // $bmd = $this->db->get(); - // return $bmd->result(); - // } - - // function getHist_dtlsDate($dateval) - // { - - // $this->db->select('*'); - // $this->db->from('T_Batchcard_MaintanceDetails'); - // $this->db->where('Maint_Date',$dateval); - // $bmd = $this->db->get(); - // return $bmd->result(); - // } - - - function edithist_mstr($array,$machinecode){ - - $this->db->where('Machine_Code',$machinecode ); - $this->db->update('T_Machine_Master',$array); - $mstr = $this->db->affected_rows(); - if($mstr>0) - { - - $this->db->select('Machine_Code'); - $this->db->from('T_Machine_Master'); - $this->db->order_by('CreatedOn','desc'); - $this->db->limit(1); - $res = $this->db->get(); - return $res->result(); - } - - } - - function edithist_dtl($array,$machinecode){ - $this->db->where('Machine_Code',$machinecode ); - $this->db->update('T_Machine_Details',$array); - $mdtl = $this->db->affected_rows(); - return $mdtl; - } - - function updatefilelist($array,$fileid){ - - $this->db->where('File_No',$fileid); - $this->db->update('T_Machines_file', $array); - $ar = $this->db->affected_rows(); - return $ar; - - } - - function checkMachineCategory($mc){ - - // $this->db->select('ConfigValue'); - // $this->db->from('T_ConfigDetails'); - // $this->db->where(Config_ID,'C023'); - // $this->db->like('ConfigValue',$mc); - // $query = $this->db->get(); - // //print_r($query->result()); - // return $query->result(); - - // //return $this->db->get('T_MaterialMaster'); - // } - $temp[] = '' ; - - $this->db->distinct(); - $this->db->select('ConfigValue'); - $this->db->from('T_ConfigDetails'); - $this->db->where('Config_ID','C028'); - $this->db->like('ConfigValue',$mc); - $query = $this->db->get(); - //print_r($query->result());die; - $temparr[] = '' ; - foreach($query->result() as $arr){ - $temparr[] = $arr->ConfigValue ; - } - $temp['suggestions'] = $temparr; - //print_r($temp); - - return $temp; - } - - //This function for multi file upload option (both machine and maint/br screen) - function deletefiledetails($id,$name){ - $sql = "DELETE FROM T_Machines_file WHERE File_No =".$id; - unlink("uploads/images/".$name);//this deletes the file on particular folder too - $query = $this->db->query($sql); - $ar = $this->db->affected_rows(); - return $ar; - } - - - function getHist_tbls($MachineCode){ - - $this->db->select('T_Machine_Master.*,T_Batchcard_MaintanceDetails.*,T_DepartmentDetails.DepartmentName'); - $this->db->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%d-%m-%Y') AS date", FALSE); - $this->db->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%l:%i %p') AS time", FALSE); - $this->db->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE); - $this->db->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE); - $this->db->from('T_Machine_Master'); - $this->db->join('T_Batchcard_MaintanceDetails','T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code'); - $this->db->join('T_DepartmentDetails','T_DepartmentDetails.DEPCode=T_Machine_Master.Machines_Dept'); - $this->db->join('T_Employee_Details ED1', 'ED1.EmpID = T_Batchcard_MaintanceDetails.Approved_By', 'left'); - $this->db->join('T_Employee_Details ED2', 'ED2.EmpID = T_Batchcard_MaintanceDetails.WorkDone_By', 'left'); - $this->db->where('T_Machine_Master.Machine_Code',$MachineCode); - $res = $this->db->get(); - return $res->result(); - - // $sql = "SELECT T_Machine_Master.*,T_Batchcard_MaintanceDetails.*, - // T_DepartmentDetails.DepartmentName, - // DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn, '%d-%m-%Y') as date, - // DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn, '%l:%i %p') as time, - // FROM T_Machine_Master - // LEFT JOIN T_Batchcard_MaintanceDetails ON T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code - // LEFT JOIN T_DepartmentDetails ON T_DepartmentDetails.DEPCode=T_Machine_Master.Machines_Dept - // WHERE T_Machine_Master.Machine_Code = '".$MachineCode."'" ; - // $res = $this->db->query($sql); - // return $res->result(); - - } - - - - - - function getinvoice_products() - { - - $this->db->select('product_id,product_name,product_description'); - $this->db->from('ip_products'); - $supp = $this->db->get(); - return $supp->result(); - - } - - function get_consumablematerials() - { - - $this->db->select('MaterialCode,MaterialName,'); - $this->db->from('T_MaterialMaster'); - //$this->db->where('T_MaterialMaster.Category',Consumables); - $this->db->where('T_MaterialMaster.Category like','%Consumable%'); - $supp = $this->db->get(); - return $supp->result(); - - } - - - function get_rawmaterials() - { - $this->db->select('MaterialCode,MaterialName,'); - $this->db->from('T_MaterialMaster'); - $this->db->where('T_MaterialMaster.Category like','%Raw Material%'); - $supp = $this->db->get(); - //print_r($this->db->last_query()); - return $supp->result(); - } - - - function get_packmaterials() - { - $this->db->select('MaterialCode,MaterialName,'); - $this->db->from('T_MaterialMaster'); - // $this->db->where('T_MaterialMaster.Category',Packingmaterial); - $this->db->where('T_MaterialMaster.Category like','%Packing%'); - $supp = $this->db->get(); - return $supp->result(); - } - - - function GetReclamationMaterial() - { - - $this->db->select('product_id,product_name,product_description'); - $this->db->from('ip_products'); - $this->db->join('ip_families','ip_families.family_id=ip_products.family_id'); - // $this->db->where('T_MaterialMaster.Category',Packingmaterial); - $this->db->where('ip_families.family_name like','%Reclam%'); - $supp = $this->db->get(); - return $supp->result(); - - } - - - function getMaterial() - { - $this->db->select('MaterialCode,MaterialName,'); - $this->db->from('T_MaterialMaster'); - //$this->db->where('T_MaterialMaster.Category',Consumables); - $supp = $this->db->get(); - return $supp->result(); - } - - - - function GettotalQty($MaterialCode,$date) - { - echo $model; - $dt = date('d',strtotime($date)); - $year = date('Y', strtotime($date)); - $month = date('m', strtotime($date)); - if($month<04) - { - //echo "b4finance"; - $newyr = $year - 1; - $startdate = $newyr.'-'.'04'.'-'.'01'; - - //echo $startdate; - } - else - { - //echo "after Finance"; - $startdate = $year.'-'.'04'.'-'.'01'; - // echo $startdate; - } - - $nedt= $dt; - - $newdate=$year.'-'.$month.'-'.$nedt; - - $subQuery='select T_MaterialMaster.MaterialName,T_Material_stock_history.MaterialCode,ifnull((select ifnull(sum(Quantity),0) as AddQty from T_Material_stock_history -where Transaction_type = "Add" and MaterialCode=?),0) as Addqty, -ifnull((select ifnull(sum(Quantity),0) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" -and MaterialCode=?),0) as ReduceQty from T_Material_stock_history join T_MaterialMaster on T_Material_stock_history.MaterialCode=T_MaterialMaster.MaterialCode where T_Material_stock_history.MaterialCode=? -and CreatedOn >= ? and CreatedOn<=? group by Addqty'; - - $query = $this->db->query($subQuery,array($MaterialCode,$MaterialCode,$MaterialCode,$startdate,$newdate)); - //print_r($this->db->last_query()); - return $query->result_array(); - - - } - - - function GetNetQty($MaterialCode,$date,$Supplier) - { - //echo $date; - $dt = date('d',strtotime($date)); - $year = date('Y', strtotime($date)); - $month = date('m', strtotime($date)); - - if($month<04) - { - //echo "b4finance"; - $newyr = $year - 1; - $startdate = $newyr.'-'.'04'.'-'.'01'; - - //echo $startdate; - } - - else - { - //echo "after Finance"; - $startdate = $year.'-'.'04'.'-'.'01'; - // echo $startdate; - } - - $nedt= $dt+1; - - $newdate=$year.'-'.$month.'-'.$nedt; - - -// $subQuery='select (select sum(Quantity) as AddQty from T_Material_stock_history where Transaction_type = "Add" and MaterialCode=? -// ) as Addqty,(select sum(Quantity) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" and MaterialCode=? -// ) as ReduceQty from T_Material_stock_history where MaterialCode=? and CreatedOn >= ? and CreatedOn<=? and SupplierID=? group by Addqty'; - - - $subQuery='select ifnull((select ifnull(sum(Quantity),0) as AddQty from T_Material_stock_history -where Transaction_type = "Add" and MaterialCode=? and SupplierID=? ),0) as Addqty, -ifnull((select ifnull(sum(Quantity),0) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" -and MaterialCode=? and SupplierID=? ),0) as ReduceQty from T_Material_stock_history where MaterialCode=? -and CreatedOn >= ? and CreatedOn<=? and SupplierID=? group by Addqty'; - - $query = $this->db->query($subQuery,array($MaterialCode,$Supplier,$MaterialCode,$Supplier,$MaterialCode,$startdate,$newdate,$Supplier)); - //print_r($this->db->last_query()); - return $query->result_array(); - - - } - - - function GetMaterialHistory($AdjustmentId) - { - $this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName'); - $this->db->from('T_Material_Adjustment'); - $this->db->join('T_SupplierDetailsN',"T_SupplierDetailsN.SupplierID=T_Material_Adjustment.SupplierID"); - $this->db->join('T_MaterialMaster',"T_MaterialMaster.MaterialCode=T_Material_Adjustment.MaterialCode"); - $this->db->where('T_Material_Adjustment.AdjustmentId',$AdjustmentId); - $supp = $this->db->get(); - return $supp->result(); - - join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left"); - } - - - - - function AddmaterialAdjustment($adjustmentaarray) - { - $this->db->trans_start(); - $this->db->insert('T_Material_Adjustment',$adjustmentaarray); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - //print_r($insert_id); - if($insert_id>0) - { - $subQuery = 'select max(AdjustmentId) as AdjustmentId from T_Material_Adjustment'; - $query = $this->db->query($subQuery); - - return $query->result(); - } - } - - - function AddMaterialHistory($historytable) - { - $this->db->trans_start(); - $this->db->insert('T_Material_stock_history',$historytable); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; - - } - - - function insert_final_product($final_master) - { - $this->db->trans_start(); - $this->db->insert('T_FinalProduct_Master',$final_master); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - //print_r($insert_id); - if($insert_id>0) - { - $subQuery = 'select max(FPId) as PId from T_FinalProduct_Master'; - $query = $this->db->query($subQuery); - - return $query->result(); - } - } - - - function save_finalraw($rawarray) - { - $this->db->trans_start(); - $this->db->insert('T_FinalProduct_RawMaterials',$rawarray); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - - } - - - function save_finalcon($conarray) - { - $this->db->trans_start(); - $this->db->insert('T_FinalProduct_ConsumableMaterials',$conarray); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - } - - function save_finalpacking($packarray) - { - $this->db->trans_start(); - $this->db->insert('T_FinalProduct_PackingMaterials',$packarray); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - } - - - function save_finalcoproduct($coparray) - { - - //print_r($coparray); - $this->db->trans_start(); - $this->db->insert('T_FinalProduct_CoProduct_Materials',$coparray); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - } - - - function getAllMaterialAdjustments() - { - $this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName'); - $this->db->from('T_Material_Adjustment'); - $this->db->join('T_SupplierDetailsN', 'T_Material_Adjustment.SupplierID = T_SupplierDetailsN.SupplierID'); - $this->db->join('T_MaterialMaster', 'T_MaterialMaster.MaterialCode = T_Material_Adjustment.MaterialCode'); - $res = $this->db->get(); - return $res->result(); - } - - - - - function save_rawmaterialto_materialHistory($materialhistory) - { - $this->db->trans_start(); - $this->db->insert('T_Material_stock_history',$materialhistory); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - } - - - function getFinalProductDetaisl() - { - $this->db->select('T_FinalProduct_Master.*,product_name,product_description'); - $this->db->from('T_FinalProduct_Master'); - $this->db->join('ip_products','ip_products.product_id=T_FinalProduct_Master.MaterialCode'); - $this->db->order_by('T_FinalProduct_Master.FPId','desc'); - $res = $this->db->get(); - return $res->result(); - - } - - - function getmasterProductDetails($FPId) - { - $this->db->select('T_FinalProduct_Master.*,product_name,product_description'); - $this->db->from('T_FinalProduct_Master'); - $this->db->join('ip_products','ip_products.product_id=T_FinalProduct_Master.MaterialCode'); - $this->db->where('T_FinalProduct_Master.FPId',$FPId); - $res = $this->db->get(); - return $res->result(); - } - - - function getrawmaterialDetails($FPId) - { - $this->db->select('T_FinalProduct_RawMaterials.*,SupplierName,MaterialName'); - $this->db->from('T_FinalProduct_RawMaterials'); - $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_RawMaterials.MaterialCode'); - $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_RawMaterials.SupplierID'); - $this->db->where('T_FinalProduct_RawMaterials.FPId',$FPId); - $res = $this->db->get(); - return $res->result(); - } - - - function getconsumaterialDetails($FPId) - { - $this->db->select('T_FinalProduct_ConsumableMaterials.*,SupplierName,MaterialName'); - $this->db->from('T_FinalProduct_ConsumableMaterials'); - $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_ConsumableMaterials.MaterialCode'); - $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_ConsumableMaterials.SupplierID'); - $this->db->where('T_FinalProduct_ConsumableMaterials.FPId',$FPId); - $res = $this->db->get(); - return $res->result(); - } - - - function getpackagematerialDetails($FPId) - { - $this->db->select('T_FinalProduct_PackingMaterials.*,SupplierName,MaterialName'); - $this->db->from('T_FinalProduct_PackingMaterials'); - $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_PackingMaterials.MaterialCode'); - $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_PackingMaterials.SupplierID'); - $this->db->where('T_FinalProduct_PackingMaterials.FPId',$FPId); - $res = $this->db->get(); - return $res->result(); - } - - - function getcoproductmaterial($FPId) - { - $subQuery ='select T_FinalProduct_CoProduct_Materials.*,product_name - from T_FinalProduct_CoProduct_Materials - join ip_products on ip_products.product_id = T_FinalProduct_CoProduct_Materials.MaterialCode - where T_FinalProduct_CoProduct_Materials.FPId=?'; - - $query = $this->db->query($subQuery,array($FPId)); - - return $query->result_array(); - - } - - - function update_final_product($final_master,$FPId) - { - //print_r($final_master); - $this->db->where('FPId', $FPId); - $this->db->update('T_FinalProduct_Master', $final_master); - $insert_id = $this->db->affected_rows(); - //return TRUE; - if($insert_id>0) - { - $subQuery = 'select max(FPId) as FPId from T_FinalProduct_Master'; - - $query = $this->db->query($subQuery,array()); - - return $query->result_array(); - } - } - - - - function GetRawid($rawilneno) - { - $this->db->select('*'); - $this->db->from('T_FinalProduct_RawMaterials'); - $this->db->where('RawId',$rawilneno); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); - } - - - - function Getconsuid($consuline) - { - $this->db->select('*'); - $this->db->from('T_FinalProduct_ConsumableMaterials'); - $this->db->where('ConId',$consuline); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); - } - - - function Getpackid($packlineId) - { - - $this->db->select('*'); - $this->db->from('T_FinalProduct_PackingMaterials'); - $this->db->where('PackId',$packlineId); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); - } - - - function Getcopid($coplineId) - { - $this->db->select('*'); - $this->db->from('T_FinalProduct_CoProduct_Materials'); - $this->db->where('CoId',$coplineId); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); - - } - - - function update_finalraw($rawarray,$rawilneno) - { - $this->db->where('RawId', $rawilneno); - $this->db->update('T_FinalProduct_RawMaterials', $rawarray); - return TRUE; - } - - - function GetRawCheck($rawmaterial,$final_product_id) - { - $this->db->select('*'); - $this->db->from('T_Material_stock_history'); - $this->db->where('MaterialCode',$rawmaterial); - $this->db->where('Ref_No',$final_product_id); - $this->db->where('Ref_Type',FinalProduct); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); - } - - - function update_rawmaterialto_materialHistory($rawmaterialhistory,$rawmaterial,$FPID) - { - $this->db->where('Ref_No', $FPID); - $this->db->where('MaterialCode', $rawmaterial); - $this->db->update('T_Material_stock_history', $rawmaterialhistory); - return TRUE; - } - - - function update_finalconsu($conarray,$consuline) - { - $this->db->where('ConId', $consuline); - $this->db->update('T_FinalProduct_ConsumableMaterials', $conarray); - return TRUE; - } - - - function update_finalpacking($conarray,$packlineId) - { - $this->db->where('PackId', $packlineId); - $this->db->update('T_FinalProduct_PackingMaterials', $conarray); - return TRUE; - } - - - function update_finalcoproduct($coparray,$coplineId) - { - $this->db->where('CoId', $coplineId); - $this->db->update('T_FinalProduct_CoProduct_Materials', $coparray); - return TRUE; - } - function getEditMaterialAdjustments($AdjustmentId) - { - - $this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName,Description,AdjustmentId,ActualQuantity,T_Material_stock_history.Quantity,Ref_Type,Transaction_type'); - $this->db->from('T_Material_Adjustment'); - $this->db->join('T_Material_stock_history', 'T_Material_Adjustment.AdjustmentId = T_Material_stock_history.Ref_No and T_Material_stock_history.Ref_Type="Adjust"'); - $this->db->join('T_SupplierDetailsN', 'T_Material_Adjustment.SupplierID = T_SupplierDetailsN.SupplierID'); - $this->db->join('T_MaterialMaster', 'T_MaterialMaster.MaterialCode = T_Material_Adjustment.MaterialCode'); - $this->db->where('T_Material_Adjustment.AdjustmentId',$AdjustmentId); - $res = $this->db->get(); - return $res->result(); - } - function material_name(){ - $sql="SELECT distinct MaterialName FROM T_MaterialMaster;"; - $query = $this->db->query($sql); - return $query->result(); - } - function getMaterial_history($prod,$frm,$t) - { - $sql="SELECT msh.StockId,sd.SupplierName,mm.MaterialName,msh.Transaction_type,msh.Ref_Type,msh.Ref_No,msh.Quantity,msh.ItemValue,date_format(msh.UpdatedOn,'%d-%m-%Y') as updatedOn FROM T_Material_stock_history as msh - left join T_SupplierDetailsN as sd on sd.SupplierID=msh.SupplierID - left join T_MaterialMaster as mm on mm.MaterialCode=msh.MaterialCode - where msh.StockId != 'null' "; - if ($prod!= ''){ - - $sql.=" and mm.MaterialName = '".$prod."' "; - - } - if ($frm and $t != ''){ - $fromd= date("Y-m-d",strtotime($frm)); - $tod=date("Y-m-d",strtotime($t)); - - - $sql.="and date(msh.UpdatedOn) >= '".$fromd."' - and date(msh.UpdatedOn) <= '".$tod."'"; - - } - - - $query =$this->db->query($sql); - return $query->result(); - - - } - //created by TamilBala - //for update quantity stockhistory - function updateQuantityStockHistory($updatequantity,$id) - { - - $this->db->where('Ref_No',$id); - $this->db->where('Ref_Type',Adjust); - $this->db->update('T_Material_stock_history',$updatequantity); - $r = $this->db->affected_rows(); - //return $r->result(); - //echo "HIS"; - - } - - //created by TamilBala - //for update quantity T_Material_Adjustment - - function updateQuantityAdjusment($updatequantitydes,$id) - { - $this->db->where('AdjustmentId',$id); - $this->db->update('T_Material_Adjustment',$updatequantitydes); - $r = $this->db->affected_rows(); - return $r; - - } - //created by TamilBala - //for update isactive T_Material_Adjustment - function updateisactiveadjusment($Updateactive,$AdjustmentId) - { - $this->db->where('AdjustmentId',$AdjustmentId); - $this->db->update('T_Material_Adjustment',$Updateactive); - $r = $this->db->affected_rows(); - return $r; - - } - - //created by TamilBala - //for update isactive stockhistory - function updateisactiveastockhistory($Updateactive,$AdjustmentId) - { - $this->db->where('Ref_No',$AdjustmentId); - $this->db->where('Ref_Type',Adjust); - $this->db->update('T_Material_stock_history',$Updateactive); - $r = $this->db->affected_rows(); - return $r; - } - - - -// function GetFinishedProductList($starting_date,$end_date,$product_id) -// { - - -// $subQuery ='select ip_products.product_id,ip_products.product_name,ip_invoices.invoice_id,ip_invoice_items.item_quantity,ip_invoice_items.item_price,ip_invoices.invoice_number as IDnumber,ip_invoices.receivedstatus as Type from ip_products join ip_invoice_items on ip_products.product_id = ip_invoice_items.item_product_id join ip_invoices on ip_invoice_items.invoice_id = ip_invoices.invoice_id -// join T_FinalProduct_Master on ip_products.product_id = T_FinalProduct_Master.MaterialCode where (ip_invoices.invoice_date_modified>=? and ip_invoices.invoice_date_modified<=? and ip_invoice_items.item_product_id=?) union - -// select ip_products.product_id,ip_products.product_name,T_FinalProduct_Master.FPId,T_FinalProduct_Master.Quantity,T_FinalProduct_Master.Price,T_FinalProduct_Master.FPId as IDnumber,T_FinalProduct_Master.ProductType as Type from ip_products join ip_invoice_items on ip_products.product_id = ip_invoice_items.item_product_id -// join T_FinalProduct_Master on ip_products.product_id = T_FinalProduct_Master.MaterialCode where -// (T_FinalProduct_Master.ProductDate<=? and T_FinalProduct_Master.ProductDate>=? and T_FinalProduct_Master.MaterialCode=?) group by FPId'; - -// $query = $this->db->query($subQuery,array($starting_date,$end_date,$product_id,$end_date,$starting_date,$product_id)); - -// //print_r($this->db->last_query()); - - -// return $query->result_array(); - - -// } - - -function GetFinishedProductList($starting_date,$end_date,$product_id) -{ - - - // $subQuery = 'select * from T_FinalProduct_History,ip_products.product_name - // join ip_products on T_FinalProduct_History.ProductCode = ip_products.product_id - - // where ProductCode=? - // and Transactiondate >= ? and Transactiondate <= ?'; - - $subQuery='select RefID,ProductCode,product_description,Quantity,Price,Transactiondate,TransactionType,product_name -from T_FinalProduct_History -join ip_products on ip_products.product_id= T_FinalProduct_History.ProductCode -where ProductCode=? and Transactiondate >= ? and Transactiondate <= ?'; - - -// $subQuery='select FPId as RefID,product_id as ProductCode,Quantity,product_description,Price,ProductDate as Transactiondate,ProductType as TransactionType,product_name from T_FinalProduct_Master join ip_products on ip_products.product_id= T_FinalProduct_Master.MaterialCode where MaterialCode=? and ProductDate >= ? and ProductDate <= ?'; - - $query = $this->db->query($subQuery,array($product_id,$starting_date,$end_date)); -// print_r($this->db->last_query()); - return $query->result_array(); - -} - - - function SaveFinalHistory($final_history) - { - $this->db->trans_start(); - $this->db->insert('T_FinalProduct_History',$final_history); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - } - - - function UpdateFinalHistory($final_history,$FPID,$rawmaterial) - { - //print_r($final_history); - $this->db->where('RefID', $FPID); - $this->db->where('ProductCode',$rawmaterial); - $this->db->update('T_FinalProduct_History',$final_history); - //print_r($this->db->last_query()); - return TRUE; - } - - function GetAvgPrice($MaterialCode,$date,$Supplier) - { - $subQuery='select AVG(Rate) as avg_rate from T_PurchaseOrder_LineItem -join T_PurchaseOrder_Master on T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO -where MaterialCode = ? and SupplierID=?'; - - $query = $this->db->query($subQuery,array($MaterialCode,$Supplier)); - //print_r($this->db->last_query()); - return $query->result_array(); - } - - - - - function Get_Product_Supplier($MaterialCode,$type) - { - //echo $MaterialCode; - $ltype='%'.$type.'%'; - //echo $ltype; - $this->db->select('mas.SupplierID,sup.SupplierName,mmas.MaterialCode,mmas.MaterialName'); - $this->db->from('T_PurchaseOrder_Master mas'); - $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); - $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); - $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); - $this->db->where('Category like',$ltype); - - // $this->db->where('T_MaterialMaster.Category like','%Raw Material%'); - $this->db->where('mmas.MaterialCode',$MaterialCode); - $this->db->group_by('SupplierID'); - $supp = $this->db->get(); - - - //print_r($this->db->last_query());die(); - return $supp->result(); - - } - - - - function getSalesProductvalue() - { - $this->db->select('product_id,product_price'); - $this->db->from('ip_products'); - $price = $this->db->get(); - return $price->result(); - } - - - - function finyear(){ - - $sql="SELECT - CASE WHEN MONTH(MaterialRcvdDate)>=4 - THEN concat(YEAR(MaterialRcvdDate), '-',YEAR(MaterialRcvdDate)+1) - ELSE concat(YEAR(MaterialRcvdDate)-1,'-', YEAR(MaterialRcvdDate)) - END AS financial_year - FROM T_IGR_Master - GROUP BY financial_year"; - $query = $this->db->query($sql); - - // print_r($this->db->last_query());die(); - return $query->result(); - - } - - - - function GetStockAbstract($search) - { - // echo 'in'; - - $fdate = $search['from_date']; - $fromdate = date("Y-m-d", strtotime($fdate) ); - - $tdate = $search['to_date']; - $todate = date("Y-m-d", strtotime($tdate) ); - - $currentyr = date("Y"); - - - - $finyear = $search['year']; - -$pieces = explode("-", $finyear);///fin year -//print_r($search); die(); -$startyr = $pieces['0']; -$endyr = $pieces['1']; - -//echo $search['month'].'-'.$startyr.'-'. $endyr;die(); - -//echo $endyr;die(); - - -$subquery="SELECT - DISTINCT(p.MaterialCode) AS ProductID,Ref_No,Date(CreatedOn),mm.MaterialName,stock,MaterialType,Category,stockdate,mm.Category,ip.product_name,ip.product_id, - SUM(IF(p.Transaction_type='Add',p.Quantity,0)) AS Addition, - SUM(IF(p.Transaction_type='Reduce',p.Quantity,0)) AS Reduce, - SUM((IF(p.Transaction_type='Add',p.Quantity,0))-(IF(p.Transaction_type='Reduce',p.Quantity,0))) AS AvailableStock,ROUND(AVG(Rate),2) as Avg_rate,ROUND(AVG(ItemValue),2) as Final_avg -FROM - T_Material_stock_history AS p -left join T_MaterialMaster mm on mm.MaterialCode = p.MaterialCode - -left join ip_products ip on ip.product_id=p.MaterialCode -left join T_PurchaseOrder_LineItem pol on pol.MaterialCode = mm.MaterialCode - "; - - -if($search['month']=='' && $startyr =='') -{ - - - if($search['from_date'] != '') - { - - $subquery.=" left join (select StockId,pp.MaterialCode mc, -SUM((IF(pp.Transaction_type='Add',Quantity,0))-(IF(pp.Transaction_type='Reduce',Quantity,0))) -AS OpeningStock -FROM T_Material_stock_history AS pp -where pp.CreatedOn < '".$fromdate."' -GROUP BY pp.MaterialCode -) as opens on opens.mc = p.MaterialCode"; - } - - -} - - -else if($search['month']!='' && $startyr !='') -{ - - - - if($search['month']!='') - { - $subquery.=" left join (select StockId,pq.MaterialCode mc, -SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0))) -AS OpeningStock -FROM T_Material_stock_history AS pq -where month(pq.CreatedOn) < '".$search['month']."' -GROUP BY pq.MaterialCode -) as opens on opens.mc = p.MaterialCode"; - - } - -} - -else if($search['month']!='' && $startyr =='') -{ - - - - $subquery.=" left join (select StockId,pq.MaterialCode mc, -SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0))) -AS OpeningStock -FROM T_Material_stock_history AS pq -where date(pq.CreatedOn) < '".$currentyr.'-'.$search['month']."-01' -GROUP BY pq.MaterialCode -) as opens on opens.mc = p.MaterialCode"; - -} - - -else if($search['month']=='' && $startyr !='' ) -{ - - // if($search['month']!='') - // { - $subquery.=" left join (select StockId,pq.MaterialCode mc, -SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0))) -AS OpeningStock -FROM T_Material_stock_history AS pq -where date(pq.CreatedOn) < '".$startyr."-03-31' -GROUP BY pq.MaterialCode -) as opens on opens.mc = p.MaterialCode"; - - // } - -} - - - - -//$subquery.=" where mm.IsActive='1'"; - -if($search['month']=='' && $startyr =='') -{ - - if($search['from_date'] != '') - { - - $subquery.=" where date(p.CreatedOn)>= '".$fromdate."'"; - } - - if($search['to_date'] != '') - { - //$subquery. = " and date(p.CreatedOn)<='".$todate."'"; - - $subquery.=" and date(p.CreatedOn)<= '".$todate."'"; - } - -} - -else -{ - - if($search['month']!='' && $startyr =='') - { - $subquery.=" where date(p.CreatedOn)>= '".$currentyr.'-'.$search['month']."-01' and - - date(p.CreatedOn)<='".$currentyr.'-'.$search['month']."-31'"; - } - - - if($search['month']!='' && $startyr !='') - { - $subquery.=" where month(p.CreatedOn)= '".$search['month']."' and date(p.CreatedOn)>= '".$startyr."-04-01' and date(p.CreatedOn)<= '".$endyr."-03-31'"; - } - - if($startyr !='' && $search['month']=='') - { - $subquery.=" where date(p.CreatedOn)>= '".$startyr."-04-01' and date(p.CreatedOn)<= '".$endyr."-03-31'"; - } - -} - - -$subquery.=" and (mm.Category like '%Consumable%' or mm.Category like '%Raw Material%' - or mm.Category like '%Packing%' or mm.Category like '%Reclam%' or mm.Category like '%Finish%' or mm.Category like '%Final%' )"; - -$subquery.=" GROUP BY p.MaterialCode"; -//$subquery. = "GROUP BY p.MaterialCode"; - -$query = $this->db->query($subquery,array()); - -//print_r($query->result());die(); - -//print_r($this->db->last_query());die(); - - return $query->result(); - - - } - - - - - function GetStockAbstractdetails($search) - { - // echo 'in'; - - $fdate = $search['fdate']; - - if($fdate != '0') - { - $fromdate = date("Y-m-d", strtotime($fdate) ); - } - - else - { - $fromdate =''; - - } - - $tdate = $search['tdate']; - - if($tdate != '0') - { - $todate = date("Y-m-d", strtotime($tdate) ); - } - - else - { - $todate = ''; - } - //echo $todate;die(); - - $finyear = $search['year']; - -$pieces = explode("-", $finyear);///fin year -//print_r($search); die(); -$startyr = $pieces['0']; -$endyr = $pieces['1']; - -//echo $endyr;die(); - - -$subquery="SELECT - DISTINCT(p.MaterialCode) AS ProductID,Ref_No,Date(CreatedOn) as Cdate,mm.MaterialName,stock,MaterialType,Category,stockdate,p.Transaction_type,Ref_Type, Ref_No,ip.product_name,invoice_number, - SUM(IF(p.Transaction_type='Add',Quantity,0)) AS Addition, - SUM(IF(p.Transaction_type='Reduce',Quantity,0)) AS Reduce, - SUM((IF(p.Transaction_type='Add',Quantity,0))-(IF(p.Transaction_type='Reduce',Quantity,0))) AS AvailableStock -FROM - T_Material_stock_history AS p -left join T_MaterialMaster mm on mm.MaterialCode = p.MaterialCode -left join ip_products ip on ip.product_id=p.MaterialCode -left join ip_invoices inv on inv.invoice_id=p.Ref_No -where p.MaterialCode='".$search['materialcode']."' - "; - - - - -if($search['month']=='' && $startyr =='' && $endyr =='') -{ - - if($fromdate != '') - { - - //echo "sv";die(); - - $subquery.=" and date(p.CreatedOn)>= '".$fromdate."'"; - } - - if($todate != '') - { - //$subquery. = " and date(p.CreatedOn)<='".$todate."'"; - - $subquery.=" and date(p.CreatedOn)<= '".$todate."'"; - } - -} - -else -{ - - if($search['month']!='') - { - $subquery.=" and month(p.CreatedOn)>= '".$search['month']."'"; - } - - if($startyr !='' && $endyr !='') - { - $subquery.=" and date(p.CreatedOn)>= '".$startyr."-04-01' and date(p.CreatedOn)<= '".$endyr."-03-31'"; - } - -} - - - - -$subquery.=" GROUP BY p.CreatedOn"; -//$subquery. = "GROUP BY p.MaterialCode"; - -$query = $this->db->query($subquery,array()); -//print_r($this->db->last_query());die(); - - return $query->result(); - - - } - - - - public function GetMaterialCode($itemproductid) - { - $this->db->select('MaterialCode'); - $this->db->from('ip_products'); - $this->db->where('product_id',$itemproductid); - $query = $this->db->get(); - // print_r( $this->db->last_query()); - return $query->result(); - - } - - - public function Delete_ProductBatchCard($FPId) - { - - $this->db->where('FPId', $FPId); - $this->db->delete('T_FinalProduct_ConsumableMaterials'); - - - $this->db->where('FPId', $FPId); - $this->db->delete('T_FinalProduct_CoProduct_Materials'); - - $this->db->where('RefID', $FPId); - $this->db->delete('T_FinalProduct_History'); - - - $this->db->where('FPId', $FPId); - $this->db->delete('T_FinalProduct_Master'); - - - - $this->db->where('FPId', $FPId); - $this->db->delete('T_FinalProduct_PackingMaterials'); - - - $this->db->where('FPId', $FPId); - $this->db->delete('T_FinalProduct_RawMaterials'); - - $this->db->where('Ref_No', $FPId); - $this->db->delete('T_Material_stock_history'); - - return true; - - - } - - - -} - +db->select('T_Employee_Details.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Employee_Details.Departmentcode,T_DepartmentDetails.shortName'); + $this->db->from('T_Employee_Details'); + $this->db->join('T_DepartmentDetails','T_Employee_Details.Departmentcode=T_DepartmentDetails.DEPCode'); + //$this->db->join('ip_invoice_items','ip_invoices.invoice_number=ip_invoice_items.invoice_number'); + //$this->db->join('ip_products','ip_invoice_items.item_product_id=ip_products.product_id'); + //$this->db->join('ip_invoice_custom','ip_invoices.invoice_number=ip_invoice_custom.invoice_number and invoice_custom_fieldid=62'); + $this->db->order_by('T_Employee_Details.EmpID'); + $res = $this->db->get(); + return $res->result(); + + } + + function getSupplierlist(){ + + $this->db->select('SupplierName,SupplierID'); + $this->db->from('T_SupplierDetailsN'); + $supp = $this->db->get(); + return $supp->result(); + + } + + + + function Rawsupplier() + { + + $this->db->select('mas.SupplierID,sup.SupplierName,mmas.MaterialCode,mmas.MaterialName'); + $this->db->from('T_PurchaseOrder_Master mas'); + $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); + $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); + $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); + $this->db->where('Category','Raw Material'); + $this->db->group_by('SupplierID'); + $supp = $this->db->get(); + + + // print_r($this->db->last_query());die(); + return $supp->result(); + + + } + + + + function Consupplier() + { + $this->db->select('mas.SupplierID,sup.SupplierName'); + $this->db->from('T_PurchaseOrder_Master mas'); + $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); + $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); + $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); + $this->db->where('Category','Consumables'); + $this->db->group_by('SupplierID'); + $supp = $this->db->get(); + return $supp->result(); + } + + + + function Pacsupplier() + { + $this->db->select('mas.SupplierID,sup.SupplierName'); + $this->db->from('T_PurchaseOrder_Master mas'); + $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); + $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); + $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); + $this->db->where('Category','Packing material'); + $this->db->group_by('SupplierID'); + $supp = $this->db->get(); + return $supp->result(); + + } + + + function getStockValue() + { + $this->db->select('MaterialCode,stock,stockdate'); + $this->db->from('T_MaterialMaster'); + $supp = $this->db->get(); + return $supp->result(); + } + + function saveHourlyBatchInfo($datatostore) + { + $this->db->insert('T_hourly_batch_info',$datatostore); + $res = $this->db->affected_rows(); + + return $res; + } + + function saveDailyBatchCardData($datatostore) + { + $this->db->insert('T_daily_batchcard_data',$datatostore); + $res = $this->db->affected_rows(); + return $res; + } + + function updateHourlyBatchInfo($datatostore,$hid) + { + $this->db->where('hourlyid',$hid); + $this->db->update('T_hourly_batch_info',$datatostore); + $res = $this->db->affected_rows(); + + return $res; + } + + function getAllHourlyData($hid='',$from='',$to='') + { + //echo "Model".$from.'-'.$to; + + $this->db->select('T_hourly_batch_info.*,T_Employee_Details.FirstName as F,T_Employee_Details.LastName as L'); + $this->db->from('T_hourly_batch_info'); + $this->db->join('tbl_users','T_hourly_batch_info.checkedby=tbl_users.userId'); + $this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID'); + if(!empty($hid)) + { + $this->db->where('hourlyid',$hid); + } + if(!empty($from) && !empty($to)) + { + $this->db->where('T_hourly_batch_info.report_date <=',$to); + $this->db->where('T_hourly_batch_info.report_date >=',$from); + } + $this->db->order_by('hourlyid','desc'); + $res = $this->db->get(); + //print_r($res->result());die(); + return $res->result(); + } + + + function checkExistHourlyData($bdate,$btime) + { + //echo 'Model'.$bdate.'-'.$btime; + $this->db->select('count(*) as count'); + $this->db->from('T_hourly_batch_info'); + $this->db->where('report_date',$bdate); + $this->db->where('report_time',$btime); + $res = $this->db->get(); + return $res->result(); + } + + + function getPowerConsumptionDetails($rdate) + { + + $this->db->select('hourlyid,report_time,opening_trp_reading,close_trp_reading,auto_start,auto_stop'); + $this->db->from('T_hourly_batch_info'); + $this->db->where('report_date',$rdate); + $res = $this->db->get(); + return $res->result(); + } + + function getDailyBatchCardData($month) + { + // $this->db->select('*'); + // $this->db->from('T_daily_batchcard_data'); + // $this->db->where('month(ddate)',$month); + $sql = 'select T_daily_batchcard_data.*,T_Employee_Details.FirstName,T_Employee_Details.LastName from T_daily_batchcard_data + join tbl_users on T_daily_batchcard_data.createdby = tbl_users.userId + join T_Employee_Details on T_Employee_Details.EmpID = tbl_users.EmpID + where month(ddate) = ?'; + $res = $this->db->query($sql,array($month)); + return $res->result(); + } + + function getIndividualDailyData($did) + { + + $this->db->select('*'); + $this->db->from('T_daily_batchcard_data'); + $this->db->where('dailyid',$did); + $res = $this->db->get(); + return $res->result(); + + } + + function checkExistDaily($rdate) + { + $this->db->select('count(*) as count'); + $this->db->from('T_daily_batchcard_data'); + $this->db->where('ddate',$rdate); + $res = $this->db->get(); + return $res->result(); + } + + function updateDailyBatchCardData($datatostore,$did) + { + $this->db->where('dailyid',$did); + $this->db->update('T_daily_batchcard_data',$datatostore); + $res = $this->db->affected_rows(); + + return $res; + } + + function checkAbstractReport($date) + { + $this->db->select('count(*) as count'); + $this->db->from('T_abstract_report'); + //$this->db->where('abstract_report_date',$date); + $this->db->where("date_format(abstract_report_date,'%Y-%m')",$date); + $res = $this->db->get(); + return $res->result(); + } + + function saveAbstractReport($datatostore) + { + $this->db->insert('T_abstract_report',$datatostore); + $res = $this->db->affected_rows(); + return $res; + } + + function updateAbstractReport($datatostore,$date,$abstract_details) + { + //$this->db->where('abstract_report_date',$date); + $this->db->where("date_format(abstract_report_date,'%Y-%m')",$date); + $this->db->where('abstract_details',$abstract_details); + $this->db->update('T_abstract_report',$datatostore); + $res = $this->db->affected_rows(); + + return $res; + + } + + function getPreviousMonthAbstractDetails($month,$year) + { + //$sql = "select abstract_details,close_stock from T_abstract_report where month(abstract_report_date) =? and year(abstract_report_date) =? "; + $sql = "select abstract_details,close_stock as Available from T_abstract_report where month(abstract_report_date) =? and year(abstract_report_date) =? "; + $res = $this->db->query($sql,array($month,$year)); + return $res->result(); + + } + + function getMonthAbstractDetails($month_year) + { + $sql = "select abstract_details,close_stock,open_stock as Available,physical_stock from T_abstract_report where date_format(abstract_report_date,'%Y-%m') = ? "; + $res = $this->db->query($sql,array($month_year)); + + return $res->result(); + } + + function getPreviousMonthClosedStockDetails($y,$m,$sn) + { + $month = 'month(ddate)'; + $year = 'year(ddate)'; + //$this->db->select($sn); + $this->db->select($sn,'ddate'); + $this->db->from('T_daily_batchcard_data'); + $this->db->where($month,$m); + $this->db->where($year,$y); + $this->db->order_by('ddate','desc'); + $this->db->limit(1); + $res = $this->db->get(); + //print_r($res->result()); + return $res->result(); + } + + function currentMonthStockDetails($m,$y,$sd1,$sd2) + { + $month = 'month(ddate)'; + $year = 'year(ddate)'; + $list = array('ddate',$sd1,$sd2); + $this->db->select($list); + $this->db->from('T_daily_batchcard_data'); + $this->db->where($month,$m); + $this->db->where($year,$y); + $this->db->order_by('ddate','asc'); + $res = $this->db->get(); + //print_r($res->result()); + return $res->result(); + } + + function addmaint_dtl($array) + { + // $this->db->insert('T_Batchcard_MaintanceDetails',$array); + // $bmd = $this->db->affected_rows(); + // return $bmd; + + $this->db->insert('T_Batchcard_MaintanceDetails',$array); + $bmd = $this->db->affected_rows(); + + + if($bmd>0) + { + $this->db->select('max(Maint_ID) as Maint_ID'); + $this->db->from('T_Batchcard_MaintanceDetails'); + $res = $this->db->get(); + return $res->result(); + } + } + function getmaint_dtl($fdate,$tdate,$type ) + { + + + $this->db->select('BMD.*'); + // $this->db->select() + $this->db->select('CONCAT(ED1.FirstName, " - " , ED1.LastName) AS Approver_Name', FALSE); + $this->db->select('CONCAT(ED2.FirstName, " - " , ED2.LastName) AS Worker_Name', FALSE); + $this->db->from('T_Batchcard_MaintanceDetails BMD'); + + $this->db->join('T_Employee_Details ED1', 'ED1.EmpID = BMD.Approved_By', 'left'); + $this->db->join('T_Employee_Details ED2', 'ED2.EmpID = BMD.WorkDone_By', 'left'); + + + + if ($fdate and $tdate != ''){ + + + $fromdate= date("Y-m-d",strtotime($fdate)); + $todate=date("Y-m-d",strtotime($tdate)); + + $date = "date(BMD.CreatedOn) >= '".$fromdate."' + and date( BMD.CreatedOn) <= '". $todate."'"; + $this->db->where($date); + } + + if($type!=""){ + + $this->db->where("BMD.type" ,$type); + + + } + $bmd = $this->db->get(); + return $bmd->result(); + } + + + + function getmaint_dtl_MntID($MntID) + { + + $this->db->select('*'); + $this->db->from('T_Batchcard_MaintanceDetails'); + $this->db->where('Maint_ID',$MntID); + $bmd = $this->db->get(); + return $bmd->result(); + } + + function updatemaint_dtl($array,$MntID) + { + $this->db->where('Maint_ID',$MntID); + $this->db->update('T_Batchcard_MaintanceDetails',$array); + $bmd = $this->db->affected_rows(); + + return $bmd; + } + + function maintenancesdata($date){ + + $this->db->select("bm.*,mm.Machine_Name"); + $this->db->select("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y') AS date", FALSE); + $this->db->select("DATE_FORMAT(bm.CreatedOn,'%l:%i %p') AS time", FALSE); + $this->db->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE); + $this->db->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE); + $this->db->from("T_Batchcard_MaintanceDetails bm"); + $this->db->join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left"); + $this->db->join("T_Employee_Details ED1", "bm.Approved_By = ED1.EmpID", "left"); + $this->db->join("T_Employee_Details ED2", "bm.WorkDone_By = ED2.EmpID", "left"); + $this->db->where("mm.Machines_Category = 'TRP'"); + //AND DATE_FORMAT(bm.CreatedOn,'%Y-%m-%d') = '19-04-2018' + $this->db->where("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y')",$date); + $bmd = $this->db->get(); + return $bmd->result(); + + //print_r($this->db->last_query()); + //die(); + + } + + function getmachine_codename(){ + $this->db->select('Machine_Code,Machine_Name'); + $this->db->from('T_Machine_Master'); + $res = $this->db->get(); + return $res->result(); + } + + /** Machines History/Master */ + function getdept_dtls() + { + $this->db->select('T_DepartmentDetails.DEPCode,T_DepartmentDetails.shortName'); + $this->db->from('T_DepartmentDetails'); + $this->db->where('IsActive',1); + $res = $this->db->get(); + return $res->result(); + } + + function getpono(){ + + $this->db->select('PONO'); + $this->db->from('T_PurchaseOrder_Master'); + $this->db->where('Status','ST026'); + $res = $this->db->get(); + return $res->result(); + } + + function getpo_dtls($pono){ + + // $this->db->select('T_PurchaseOrder_Master.PONO,T_PurchaseOrder_Master.SupplierID,T_SupplierDetailsN.SupplierName,DATE_FORMAT(T_PurchaseOrder_Master.PODate,"%d-%m-%Y") as PO_Date'); + // $this->db->from('T_PurchaseOrder_Master'); + // $this->db->join('T_SupplierDetailsN','T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID'); + // $this->db->where('PONO',$pono); + // $res = $this->db->get(); + // return $res->result(); + $sql = "select T_PurchaseOrder_Master.PONO,T_PurchaseOrder_Master.SupplierID,T_SupplierDetailsN.SupplierName,DATE_FORMAT(T_PurchaseOrder_Master.PODate,'%d-%m-%Y') as PO_Date + from T_PurchaseOrder_Master + join T_SupplierDetailsN on T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID + where PONO = ? "; + $res = $this->db->query($sql,array($pono)); + return $res->result(); + + } + + function addhist_mstr($array) + { + $this->db->insert('T_Machine_Master',$array); + $mstr = $this->db->affected_rows(); + //print_r($this->db->last_query()); + //print_r($mstr); + if($mstr>0) + { + + $this->db->select('Machine_Code'); + $this->db->from('T_Machine_Master'); + $this->db->order_by('CreatedOn','desc'); + $this->db->limit(1); + $res = $this->db->get(); + //print_r($res->result()); + return $res->result(); + + + + + + } + + } + function addhist_dtl($array){ + + $this->db->insert('T_Machine_Details',$array); + $child = $this->db->affected_rows(); + return $child; + + } + //This function for multi file upload option (both machine and maint/br screen) + function addfiledetails($array){ + + $this->db->insert('T_Machines_file', $array); + $r = $this->db->affected_rows(); + return $r; + //return TRUE; + + } + function insertvalueintoconfig($config){ + + $this->db->insert('T_ConfigDetails', $config); + return TRUE; + } + + //This function used to get the material category using configdetails table + function getmachineCategory($MaterialCategory = '') + { + $Config_ID = 'C028'; + $this->db->select('Config_ID,ConfigValue'); + $this->db->from('T_ConfigDetails'); + $this->db->where('Config_id',$Config_ID ); + if($MaterialCategory != '') + { + $this->db->where('ConfigValue !=',$MaterialCategory ); + } + $query = $this->db->get(); + + return $query->result(); + } + + + function getHist_dtls($MachineCode = '') + { + + $this->db->select('*'); + $this->db->from('T_Machine_Details'); + if($MachineCode != '') + { + $this->db->where('Machine_Code',$MachineCode ); + } + $bmd = $this->db->get(); + return $bmd->result(); + } + + //This function for multi file upload option (both machine and maint/br screen) + function getfiledetails($data = '') + { + + $this->db->select('*'); + $this->db->from('T_Machines_file'); + if($data != '') + { + $this->db->where('Machine_code/Maint_id',$data ); + } + $bmd = $this->db->get(); + return $bmd->result(); + } + + function getHist_mstr($MachineCode = '') + { + + $this->db->select('*'); + $this->db->from('T_Machine_Master'); + if($MachineCode != '') + { + $this->db->where('Machine_Code',$MachineCode ); + } + $bmd = $this->db->get(); + return $bmd->result(); + } + + // function getHist_dtlsID($MntID) + // { + + // $this->db->select('*'); + // $this->db->from('T_Batchcard_MaintanceDetails'); + // $this->db->where('Maint_ID',$MntID); + // $bmd = $this->db->get(); + // return $bmd->result(); + // } + + // function getHist_dtlsDate($dateval) + // { + + // $this->db->select('*'); + // $this->db->from('T_Batchcard_MaintanceDetails'); + // $this->db->where('Maint_Date',$dateval); + // $bmd = $this->db->get(); + // return $bmd->result(); + // } + + + function edithist_mstr($array,$machinecode){ + + $this->db->where('Machine_Code',$machinecode ); + $this->db->update('T_Machine_Master',$array); + $mstr = $this->db->affected_rows(); + if($mstr>0) + { + + $this->db->select('Machine_Code'); + $this->db->from('T_Machine_Master'); + $this->db->order_by('CreatedOn','desc'); + $this->db->limit(1); + $res = $this->db->get(); + return $res->result(); + } + + } + + function edithist_dtl($array,$machinecode){ + $this->db->where('Machine_Code',$machinecode ); + $this->db->update('T_Machine_Details',$array); + $mdtl = $this->db->affected_rows(); + return $mdtl; + } + + function updatefilelist($array,$fileid){ + + $this->db->where('File_No',$fileid); + $this->db->update('T_Machines_file', $array); + $ar = $this->db->affected_rows(); + return $ar; + + } + + function checkMachineCategory($mc){ + + // $this->db->select('ConfigValue'); + // $this->db->from('T_ConfigDetails'); + // $this->db->where(Config_ID,'C023'); + // $this->db->like('ConfigValue',$mc); + // $query = $this->db->get(); + // //print_r($query->result()); + // return $query->result(); + + // //return $this->db->get('T_MaterialMaster'); + // } + $temp[] = '' ; + + $this->db->distinct(); + $this->db->select('ConfigValue'); + $this->db->from('T_ConfigDetails'); + $this->db->where('Config_ID','C028'); + $this->db->like('ConfigValue',$mc); + $query = $this->db->get(); + //print_r($query->result());die; + $temparr[] = '' ; + foreach($query->result() as $arr){ + $temparr[] = $arr->ConfigValue ; + } + $temp['suggestions'] = $temparr; + //print_r($temp); + + return $temp; + } + + //This function for multi file upload option (both machine and maint/br screen) + function deletefiledetails($id,$name){ + $sql = "DELETE FROM T_Machines_file WHERE File_No =".$id; + unlink("uploads/images/".$name);//this deletes the file on particular folder too + $query = $this->db->query($sql); + $ar = $this->db->affected_rows(); + return $ar; + } + + + function getHist_tbls($MachineCode){ + + $this->db->select('T_Machine_Master.*,T_Batchcard_MaintanceDetails.*,T_DepartmentDetails.DepartmentName'); + $this->db->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%d-%m-%Y') AS date", FALSE); + $this->db->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%l:%i %p') AS time", FALSE); + $this->db->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE); + $this->db->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE); + $this->db->from('T_Machine_Master'); + $this->db->join('T_Batchcard_MaintanceDetails','T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code'); + $this->db->join('T_DepartmentDetails','T_DepartmentDetails.DEPCode=T_Machine_Master.Machines_Dept'); + $this->db->join('T_Employee_Details ED1', 'ED1.EmpID = T_Batchcard_MaintanceDetails.Approved_By', 'left'); + $this->db->join('T_Employee_Details ED2', 'ED2.EmpID = T_Batchcard_MaintanceDetails.WorkDone_By', 'left'); + $this->db->where('T_Machine_Master.Machine_Code',$MachineCode); + $res = $this->db->get(); + return $res->result(); + + // $sql = "SELECT T_Machine_Master.*,T_Batchcard_MaintanceDetails.*, + // T_DepartmentDetails.DepartmentName, + // DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn, '%d-%m-%Y') as date, + // DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn, '%l:%i %p') as time, + // FROM T_Machine_Master + // LEFT JOIN T_Batchcard_MaintanceDetails ON T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code + // LEFT JOIN T_DepartmentDetails ON T_DepartmentDetails.DEPCode=T_Machine_Master.Machines_Dept + // WHERE T_Machine_Master.Machine_Code = '".$MachineCode."'" ; + // $res = $this->db->query($sql); + // return $res->result(); + + } + + + + + + function getinvoice_products() + { + + $this->db->select('product_id,product_name,product_description'); + $this->db->from('ip_products'); + $supp = $this->db->get(); + return $supp->result(); + + } + + function get_consumablematerials() + { + + $this->db->select('MaterialCode,MaterialName,'); + $this->db->from('T_MaterialMaster'); + //$this->db->where('T_MaterialMaster.Category',Consumables); + $this->db->where('T_MaterialMaster.Category like','%Consumable%'); + $supp = $this->db->get(); + return $supp->result(); + + } + + + function get_rawmaterials() + { + $this->db->select('MaterialCode,MaterialName,'); + $this->db->from('T_MaterialMaster'); + $this->db->where('T_MaterialMaster.Category like','%Raw Material%'); + $supp = $this->db->get(); + //print_r($this->db->last_query()); + return $supp->result(); + } + + + function get_packmaterials() + { + $this->db->select('MaterialCode,MaterialName,'); + $this->db->from('T_MaterialMaster'); + // $this->db->where('T_MaterialMaster.Category',Packingmaterial); + $this->db->where('T_MaterialMaster.Category like','%Packing%'); + $supp = $this->db->get(); + return $supp->result(); + } + + + function GetReclamationMaterial() + { + + $this->db->select('product_id,product_name,product_description'); + $this->db->from('ip_products'); + $this->db->join('ip_families','ip_families.family_id=ip_products.family_id'); + // $this->db->where('T_MaterialMaster.Category',Packingmaterial); + $this->db->where('ip_families.family_name like','%Reclam%'); + $supp = $this->db->get(); + return $supp->result(); + + } + + + function getMaterial() + { + $this->db->select('MaterialCode,MaterialName,'); + $this->db->from('T_MaterialMaster'); + //$this->db->where('T_MaterialMaster.Category',Consumables); + $supp = $this->db->get(); + return $supp->result(); + } + + + + function GettotalQty($MaterialCode,$date) + { + echo $model; + $dt = date('d',strtotime($date)); + $year = date('Y', strtotime($date)); + $month = date('m', strtotime($date)); + if($month<04) + { + //echo "b4finance"; + $newyr = $year - 1; + $startdate = $newyr.'-'.'04'.'-'.'01'; + + //echo $startdate; + } + else + { + //echo "after Finance"; + $startdate = $year.'-'.'04'.'-'.'01'; + // echo $startdate; + } + + $nedt= $dt; + + $newdate=$year.'-'.$month.'-'.$nedt; + + $subQuery='select T_MaterialMaster.MaterialName,T_Material_stock_history.MaterialCode,ifnull((select ifnull(sum(Quantity),0) as AddQty from T_Material_stock_history +where Transaction_type = "Add" and MaterialCode=?),0) as Addqty, +ifnull((select ifnull(sum(Quantity),0) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" +and MaterialCode=?),0) as ReduceQty from T_Material_stock_history join T_MaterialMaster on T_Material_stock_history.MaterialCode=T_MaterialMaster.MaterialCode where T_Material_stock_history.MaterialCode=? +and CreatedOn >= ? and CreatedOn<=? group by Addqty'; + + $query = $this->db->query($subQuery,array($MaterialCode,$MaterialCode,$MaterialCode,$startdate,$newdate)); + //print_r($this->db->last_query()); + return $query->result_array(); + + + } + + + function GetNetQty($MaterialCode,$date,$Supplier) + { + //echo $date; + $dt = date('d',strtotime($date)); + $year = date('Y', strtotime($date)); + $month = date('m', strtotime($date)); + + if($month<04) + { + //echo "b4finance"; + $newyr = $year - 1; + $startdate = $newyr.'-'.'04'.'-'.'01'; + + //echo $startdate; + } + + else + { + //echo "after Finance"; + $startdate = $year.'-'.'04'.'-'.'01'; + // echo $startdate; + } + + $nedt= $dt+1; + + $newdate=$year.'-'.$month.'-'.$nedt; + + +// $subQuery='select (select sum(Quantity) as AddQty from T_Material_stock_history where Transaction_type = "Add" and MaterialCode=? +// ) as Addqty,(select sum(Quantity) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" and MaterialCode=? +// ) as ReduceQty from T_Material_stock_history where MaterialCode=? and CreatedOn >= ? and CreatedOn<=? and SupplierID=? group by Addqty'; + + + $subQuery='select ifnull((select ifnull(sum(Quantity),0) as AddQty from T_Material_stock_history +where Transaction_type = "Add" and MaterialCode=? and SupplierID=? ),0) as Addqty, +ifnull((select ifnull(sum(Quantity),0) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" +and MaterialCode=? and SupplierID=? ),0) as ReduceQty from T_Material_stock_history where MaterialCode=? +and CreatedOn >= ? and CreatedOn<=? and SupplierID=? group by Addqty'; + + $query = $this->db->query($subQuery,array($MaterialCode,$Supplier,$MaterialCode,$Supplier,$MaterialCode,$startdate,$newdate,$Supplier)); + //print_r($this->db->last_query()); + return $query->result_array(); + + + } + + + function GetMaterialHistory($AdjustmentId) + { + $this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName'); + $this->db->from('T_Material_Adjustment'); + $this->db->join('T_SupplierDetailsN',"T_SupplierDetailsN.SupplierID=T_Material_Adjustment.SupplierID"); + $this->db->join('T_MaterialMaster',"T_MaterialMaster.MaterialCode=T_Material_Adjustment.MaterialCode"); + $this->db->where('T_Material_Adjustment.AdjustmentId',$AdjustmentId); + $supp = $this->db->get(); + return $supp->result(); + + join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left"); + } + + + + + function AddmaterialAdjustment($adjustmentaarray) + { + $this->db->trans_start(); + $this->db->insert('T_Material_Adjustment',$adjustmentaarray); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + //print_r($insert_id); + if($insert_id>0) + { + $subQuery = 'select max(AdjustmentId) as AdjustmentId from T_Material_Adjustment'; + $query = $this->db->query($subQuery); + + return $query->result(); + } + } + + + function AddMaterialHistory($historytable) + { + $this->db->trans_start(); + $this->db->insert('T_Material_stock_history',$historytable); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; + + } + + + function insert_final_product($final_master) + { + $this->db->trans_start(); + $this->db->insert('T_FinalProduct_Master',$final_master); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + //print_r($insert_id); + if($insert_id>0) + { + $subQuery = 'select max(FPId) as PId from T_FinalProduct_Master'; + $query = $this->db->query($subQuery); + + return $query->result(); + } + } + + + function save_finalraw($rawarray) + { + $this->db->trans_start(); + $this->db->insert('T_FinalProduct_RawMaterials',$rawarray); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + + } + + + function save_finalcon($conarray) + { + $this->db->trans_start(); + $this->db->insert('T_FinalProduct_ConsumableMaterials',$conarray); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + } + + function save_finalpacking($packarray) + { + $this->db->trans_start(); + $this->db->insert('T_FinalProduct_PackingMaterials',$packarray); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + } + + + function save_finalcoproduct($coparray) + { + + //print_r($coparray); + $this->db->trans_start(); + $this->db->insert('T_FinalProduct_CoProduct_Materials',$coparray); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + } + + + function getAllMaterialAdjustments() + { + $this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName'); + $this->db->from('T_Material_Adjustment'); + $this->db->join('T_SupplierDetailsN', 'T_Material_Adjustment.SupplierID = T_SupplierDetailsN.SupplierID'); + $this->db->join('T_MaterialMaster', 'T_MaterialMaster.MaterialCode = T_Material_Adjustment.MaterialCode'); + $res = $this->db->get(); + return $res->result(); + } + + + + + function save_rawmaterialto_materialHistory($materialhistory) + { + $this->db->trans_start(); + $this->db->insert('T_Material_stock_history',$materialhistory); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + } + + + function getFinalProductDetaisl() + { + $this->db->select('T_FinalProduct_Master.*,product_name,product_description'); + $this->db->from('T_FinalProduct_Master'); + $this->db->join('ip_products','ip_products.product_id=T_FinalProduct_Master.MaterialCode'); + $this->db->order_by('T_FinalProduct_Master.FPId','desc'); + $res = $this->db->get(); + return $res->result(); + + } + + + function getmasterProductDetails($FPId) + { + $this->db->select('T_FinalProduct_Master.*,product_name,product_description'); + $this->db->from('T_FinalProduct_Master'); + $this->db->join('ip_products','ip_products.product_id=T_FinalProduct_Master.MaterialCode'); + $this->db->where('T_FinalProduct_Master.FPId',$FPId); + $res = $this->db->get(); + return $res->result(); + } + + + function getrawmaterialDetails($FPId) + { + $this->db->select('T_FinalProduct_RawMaterials.*,SupplierName,MaterialName'); + $this->db->from('T_FinalProduct_RawMaterials'); + $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_RawMaterials.MaterialCode'); + $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_RawMaterials.SupplierID'); + $this->db->where('T_FinalProduct_RawMaterials.FPId',$FPId); + $res = $this->db->get(); + return $res->result(); + } + + + function getconsumaterialDetails($FPId) + { + $this->db->select('T_FinalProduct_ConsumableMaterials.*,SupplierName,MaterialName'); + $this->db->from('T_FinalProduct_ConsumableMaterials'); + $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_ConsumableMaterials.MaterialCode'); + $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_ConsumableMaterials.SupplierID'); + $this->db->where('T_FinalProduct_ConsumableMaterials.FPId',$FPId); + $res = $this->db->get(); + return $res->result(); + } + + + function getpackagematerialDetails($FPId) + { + $this->db->select('T_FinalProduct_PackingMaterials.*,SupplierName,MaterialName'); + $this->db->from('T_FinalProduct_PackingMaterials'); + $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_PackingMaterials.MaterialCode'); + $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_PackingMaterials.SupplierID'); + $this->db->where('T_FinalProduct_PackingMaterials.FPId',$FPId); + $res = $this->db->get(); + return $res->result(); + } + + + function getcoproductmaterial($FPId) + { + $subQuery ='select T_FinalProduct_CoProduct_Materials.*,product_name + from T_FinalProduct_CoProduct_Materials + join ip_products on ip_products.product_id = T_FinalProduct_CoProduct_Materials.MaterialCode + where T_FinalProduct_CoProduct_Materials.FPId=?'; + + $query = $this->db->query($subQuery,array($FPId)); + + return $query->result_array(); + + } + + + function update_final_product($final_master,$FPId) + { + //print_r($final_master); + $this->db->where('FPId', $FPId); + $this->db->update('T_FinalProduct_Master', $final_master); + $insert_id = $this->db->affected_rows(); + //return TRUE; + if($insert_id>0) + { + $subQuery = 'select max(FPId) as FPId from T_FinalProduct_Master'; + + $query = $this->db->query($subQuery,array()); + + return $query->result_array(); + } + } + + + + function GetRawid($rawilneno) + { + $this->db->select('*'); + $this->db->from('T_FinalProduct_RawMaterials'); + $this->db->where('RawId',$rawilneno); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); + } + + + + function Getconsuid($consuline) + { + $this->db->select('*'); + $this->db->from('T_FinalProduct_ConsumableMaterials'); + $this->db->where('ConId',$consuline); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); + } + + + function Getpackid($packlineId) + { + + $this->db->select('*'); + $this->db->from('T_FinalProduct_PackingMaterials'); + $this->db->where('PackId',$packlineId); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); + } + + + function Getcopid($coplineId) + { + $this->db->select('*'); + $this->db->from('T_FinalProduct_CoProduct_Materials'); + $this->db->where('CoId',$coplineId); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); + + } + + + function update_finalraw($rawarray,$rawilneno) + { + $this->db->where('RawId', $rawilneno); + $this->db->update('T_FinalProduct_RawMaterials', $rawarray); + return TRUE; + } + + + function GetRawCheck($rawmaterial,$final_product_id) + { + $this->db->select('*'); + $this->db->from('T_Material_stock_history'); + $this->db->where('MaterialCode',$rawmaterial); + $this->db->where('Ref_No',$final_product_id); + $this->db->where('Ref_Type',FinalProduct); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); + } + + + function update_rawmaterialto_materialHistory($rawmaterialhistory,$rawmaterial,$FPID) + { + $this->db->where('Ref_No', $FPID); + $this->db->where('MaterialCode', $rawmaterial); + $this->db->update('T_Material_stock_history', $rawmaterialhistory); + return TRUE; + } + + + function update_finalconsu($conarray,$consuline) + { + $this->db->where('ConId', $consuline); + $this->db->update('T_FinalProduct_ConsumableMaterials', $conarray); + return TRUE; + } + + + function update_finalpacking($conarray,$packlineId) + { + $this->db->where('PackId', $packlineId); + $this->db->update('T_FinalProduct_PackingMaterials', $conarray); + return TRUE; + } + + + function update_finalcoproduct($coparray,$coplineId) + { + $this->db->where('CoId', $coplineId); + $this->db->update('T_FinalProduct_CoProduct_Materials', $coparray); + return TRUE; + } + function getEditMaterialAdjustments($AdjustmentId) + { + + $this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName,Description,AdjustmentId,ActualQuantity,T_Material_stock_history.Quantity,Ref_Type,Transaction_type'); + $this->db->from('T_Material_Adjustment'); + $this->db->join('T_Material_stock_history', 'T_Material_Adjustment.AdjustmentId = T_Material_stock_history.Ref_No and T_Material_stock_history.Ref_Type="Adjust"'); + $this->db->join('T_SupplierDetailsN', 'T_Material_Adjustment.SupplierID = T_SupplierDetailsN.SupplierID'); + $this->db->join('T_MaterialMaster', 'T_MaterialMaster.MaterialCode = T_Material_Adjustment.MaterialCode'); + $this->db->where('T_Material_Adjustment.AdjustmentId',$AdjustmentId); + $res = $this->db->get(); + return $res->result(); + } + function material_name(){ + $sql="SELECT distinct MaterialName FROM T_MaterialMaster;"; + $query = $this->db->query($sql); + return $query->result(); + } + function getMaterial_history($prod,$frm,$t) + { + $sql="SELECT msh.StockId,sd.SupplierName,mm.MaterialName,msh.Transaction_type,msh.Ref_Type,msh.Ref_No,msh.Quantity,msh.ItemValue,date_format(msh.UpdatedOn,'%d-%m-%Y') as updatedOn FROM T_Material_stock_history as msh + left join T_SupplierDetailsN as sd on sd.SupplierID=msh.SupplierID + left join T_MaterialMaster as mm on mm.MaterialCode=msh.MaterialCode + where msh.StockId != 'null' "; + if ($prod!= ''){ + + $sql.=" and mm.MaterialName = '".$prod."' "; + + } + if ($frm and $t != ''){ + $fromd= date("Y-m-d",strtotime($frm)); + $tod=date("Y-m-d",strtotime($t)); + + + $sql.="and date(msh.UpdatedOn) >= '".$fromd."' + and date(msh.UpdatedOn) <= '".$tod."'"; + + } + + + $query =$this->db->query($sql); + return $query->result(); + + + } + //created by TamilBala + //for update quantity stockhistory + function updateQuantityStockHistory($updatequantity,$id) + { + + $this->db->where('Ref_No',$id); + $this->db->where('Ref_Type',Adjust); + $this->db->update('T_Material_stock_history',$updatequantity); + $r = $this->db->affected_rows(); + //return $r->result(); + //echo "HIS"; + + } + + //created by TamilBala + //for update quantity T_Material_Adjustment + + function updateQuantityAdjusment($updatequantitydes,$id) + { + $this->db->where('AdjustmentId',$id); + $this->db->update('T_Material_Adjustment',$updatequantitydes); + $r = $this->db->affected_rows(); + return $r; + + } + //created by TamilBala + //for update isactive T_Material_Adjustment + function updateisactiveadjusment($Updateactive,$AdjustmentId) + { + $this->db->where('AdjustmentId',$AdjustmentId); + $this->db->update('T_Material_Adjustment',$Updateactive); + $r = $this->db->affected_rows(); + return $r; + + } + + //created by TamilBala + //for update isactive stockhistory + function updateisactiveastockhistory($Updateactive,$AdjustmentId) + { + $this->db->where('Ref_No',$AdjustmentId); + $this->db->where('Ref_Type',Adjust); + $this->db->update('T_Material_stock_history',$Updateactive); + $r = $this->db->affected_rows(); + return $r; + } + + + +// function GetFinishedProductList($starting_date,$end_date,$product_id) +// { + + +// $subQuery ='select ip_products.product_id,ip_products.product_name,ip_invoices.invoice_id,ip_invoice_items.item_quantity,ip_invoice_items.item_price,ip_invoices.invoice_number as IDnumber,ip_invoices.receivedstatus as Type from ip_products join ip_invoice_items on ip_products.product_id = ip_invoice_items.item_product_id join ip_invoices on ip_invoice_items.invoice_id = ip_invoices.invoice_id +// join T_FinalProduct_Master on ip_products.product_id = T_FinalProduct_Master.MaterialCode where (ip_invoices.invoice_date_modified>=? and ip_invoices.invoice_date_modified<=? and ip_invoice_items.item_product_id=?) union + +// select ip_products.product_id,ip_products.product_name,T_FinalProduct_Master.FPId,T_FinalProduct_Master.Quantity,T_FinalProduct_Master.Price,T_FinalProduct_Master.FPId as IDnumber,T_FinalProduct_Master.ProductType as Type from ip_products join ip_invoice_items on ip_products.product_id = ip_invoice_items.item_product_id +// join T_FinalProduct_Master on ip_products.product_id = T_FinalProduct_Master.MaterialCode where +// (T_FinalProduct_Master.ProductDate<=? and T_FinalProduct_Master.ProductDate>=? and T_FinalProduct_Master.MaterialCode=?) group by FPId'; + +// $query = $this->db->query($subQuery,array($starting_date,$end_date,$product_id,$end_date,$starting_date,$product_id)); + +// //print_r($this->db->last_query()); + + +// return $query->result_array(); + + +// } + + +function GetFinishedProductList($starting_date,$end_date,$product_id) +{ + + + // $subQuery = 'select * from T_FinalProduct_History,ip_products.product_name + // join ip_products on T_FinalProduct_History.ProductCode = ip_products.product_id + + // where ProductCode=? + // and Transactiondate >= ? and Transactiondate <= ?'; + + $subQuery='select RefID,ProductCode,product_description,Quantity,Price,Transactiondate,TransactionType,product_name +from T_FinalProduct_History +join ip_products on ip_products.product_id= T_FinalProduct_History.ProductCode +where ProductCode=? and Transactiondate >= ? and Transactiondate <= ?'; + + +// $subQuery='select FPId as RefID,product_id as ProductCode,Quantity,product_description,Price,ProductDate as Transactiondate,ProductType as TransactionType,product_name from T_FinalProduct_Master join ip_products on ip_products.product_id= T_FinalProduct_Master.MaterialCode where MaterialCode=? and ProductDate >= ? and ProductDate <= ?'; + + $query = $this->db->query($subQuery,array($product_id,$starting_date,$end_date)); +// print_r($this->db->last_query()); + return $query->result_array(); + +} + + + function SaveFinalHistory($final_history) + { + $this->db->trans_start(); + $this->db->insert('T_FinalProduct_History',$final_history); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + } + + + function UpdateFinalHistory($final_history,$FPID,$rawmaterial) + { + //print_r($final_history); + $this->db->where('RefID', $FPID); + $this->db->where('ProductCode',$rawmaterial); + $this->db->update('T_FinalProduct_History',$final_history); + //print_r($this->db->last_query()); + return TRUE; + } + + function GetAvgPrice($MaterialCode,$date,$Supplier) + { + $subQuery='select AVG(Rate) as avg_rate from T_PurchaseOrder_LineItem +join T_PurchaseOrder_Master on T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO +where MaterialCode = ? and SupplierID=?'; + + $query = $this->db->query($subQuery,array($MaterialCode,$Supplier)); + //print_r($this->db->last_query()); + return $query->result_array(); + } + + + + + function Get_Product_Supplier($MaterialCode,$type) + { + //echo $MaterialCode; + $ltype='%'.$type.'%'; + //echo $ltype; + $this->db->select('mas.SupplierID,sup.SupplierName,mmas.MaterialCode,mmas.MaterialName'); + $this->db->from('T_PurchaseOrder_Master mas'); + $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=mas.SupplierID'); + $this->db->join('T_PurchaseOrder_LineItem line','line.PONO=mas.PONO'); + $this->db->join('T_MaterialMaster mmas','mmas.MaterialCode=line.MaterialCode'); + $this->db->where('Category like',$ltype); + + // $this->db->where('T_MaterialMaster.Category like','%Raw Material%'); + $this->db->where('mmas.MaterialCode',$MaterialCode); + $this->db->group_by('SupplierID'); + $supp = $this->db->get(); + + + //print_r($this->db->last_query());die(); + return $supp->result(); + + } + + + + function getSalesProductvalue() + { + $this->db->select('product_id,product_price'); + $this->db->from('ip_products'); + $price = $this->db->get(); + return $price->result(); + } + + + + function finyear(){ + + $sql="SELECT + CASE WHEN MONTH(MaterialRcvdDate)>=4 + THEN concat(YEAR(MaterialRcvdDate), '-',YEAR(MaterialRcvdDate)+1) + ELSE concat(YEAR(MaterialRcvdDate)-1,'-', YEAR(MaterialRcvdDate)) + END AS financial_year + FROM T_IGR_Master + GROUP BY financial_year"; + $query = $this->db->query($sql); + + // print_r($this->db->last_query());die(); + return $query->result(); + + } + + + + function GetStockAbstract($search) + { + // echo 'in'; + + $fdate = $search['from_date']; + $fromdate = date("Y-m-d", strtotime($fdate) ); + + $tdate = $search['to_date']; + $todate = date("Y-m-d", strtotime($tdate) ); + + $currentyr = date("Y"); + + + + $finyear = $search['year']; + +$pieces = explode("-", $finyear);///fin year +//print_r($search); die(); +$startyr = $pieces['0']; +$endyr = $pieces['1']; + +//echo $search['month'].'-'.$startyr.'-'. $endyr;die(); + +//echo $endyr;die(); + + +$subquery="SELECT + DISTINCT(p.MaterialCode) AS ProductID,Ref_No,Date(CreatedOn),mm.MaterialName,stock,MaterialType,Category,stockdate,mm.Category,ip.product_name,ip.product_id, + SUM(IF(p.Transaction_type='Add',p.Quantity,0)) AS Addition, + SUM(IF(p.Transaction_type='Reduce',p.Quantity,0)) AS Reduce, + SUM((IF(p.Transaction_type='Add',p.Quantity,0))-(IF(p.Transaction_type='Reduce',p.Quantity,0))) AS AvailableStock,ROUND(AVG(Rate),2) as Avg_rate,ROUND(AVG(ItemValue),2) as Final_avg +FROM + T_Material_stock_history AS p +left join T_MaterialMaster mm on mm.MaterialCode = p.MaterialCode + +left join ip_products ip on ip.product_id=p.MaterialCode +left join T_PurchaseOrder_LineItem pol on pol.MaterialCode = mm.MaterialCode + "; + + +if($search['month']=='' && $startyr =='') +{ + + + if($search['from_date'] != '') + { + + $subquery.=" left join (select StockId,pp.MaterialCode mc, +SUM((IF(pp.Transaction_type='Add',Quantity,0))-(IF(pp.Transaction_type='Reduce',Quantity,0))) +AS OpeningStock +FROM T_Material_stock_history AS pp +where pp.CreatedOn < '".$fromdate."' +GROUP BY pp.MaterialCode +) as opens on opens.mc = p.MaterialCode"; + } + + +} + + +else if($search['month']!='' && $startyr !='') +{ + + + + if($search['month']!='') + { + $subquery.=" left join (select StockId,pq.MaterialCode mc, +SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0))) +AS OpeningStock +FROM T_Material_stock_history AS pq +where month(pq.CreatedOn) < '".$search['month']."' +GROUP BY pq.MaterialCode +) as opens on opens.mc = p.MaterialCode"; + + } + +} + +else if($search['month']!='' && $startyr =='') +{ + + + + $subquery.=" left join (select StockId,pq.MaterialCode mc, +SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0))) +AS OpeningStock +FROM T_Material_stock_history AS pq +where date(pq.CreatedOn) < '".$currentyr.'-'.$search['month']."-01' +GROUP BY pq.MaterialCode +) as opens on opens.mc = p.MaterialCode"; + +} + + +else if($search['month']=='' && $startyr !='' ) +{ + + // if($search['month']!='') + // { + $subquery.=" left join (select StockId,pq.MaterialCode mc, +SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0))) +AS OpeningStock +FROM T_Material_stock_history AS pq +where date(pq.CreatedOn) < '".$startyr."-03-31' +GROUP BY pq.MaterialCode +) as opens on opens.mc = p.MaterialCode"; + + // } + +} + + + + +//$subquery.=" where mm.IsActive='1'"; + +if($search['month']=='' && $startyr =='') +{ + + if($search['from_date'] != '') + { + + $subquery.=" where date(p.CreatedOn)>= '".$fromdate."'"; + } + + if($search['to_date'] != '') + { + //$subquery. = " and date(p.CreatedOn)<='".$todate."'"; + + $subquery.=" and date(p.CreatedOn)<= '".$todate."'"; + } + +} + +else +{ + + if($search['month']!='' && $startyr =='') + { + $subquery.=" where date(p.CreatedOn)>= '".$currentyr.'-'.$search['month']."-01' and + + date(p.CreatedOn)<='".$currentyr.'-'.$search['month']."-31'"; + } + + + if($search['month']!='' && $startyr !='') + { + $subquery.=" where month(p.CreatedOn)= '".$search['month']."' and date(p.CreatedOn)>= '".$startyr."-04-01' and date(p.CreatedOn)<= '".$endyr."-03-31'"; + } + + if($startyr !='' && $search['month']=='') + { + $subquery.=" where date(p.CreatedOn)>= '".$startyr."-04-01' and date(p.CreatedOn)<= '".$endyr."-03-31'"; + } + +} + + +$subquery.=" and (mm.Category like '%Consumable%' or mm.Category like '%Raw Material%' + or mm.Category like '%Packing%' or mm.Category like '%Reclam%' or mm.Category like '%Finish%' or mm.Category like '%Final%' )"; + +$subquery.=" GROUP BY p.MaterialCode"; +//$subquery. = "GROUP BY p.MaterialCode"; + +$query = $this->db->query($subquery,array()); + +//print_r($query->result());die(); + +//print_r($this->db->last_query());die(); + + return $query->result(); + + + } + + + + + function GetStockAbstractdetails($search) + { + // echo 'in'; + + $fdate = $search['fdate']; + + if($fdate != '0') + { + $fromdate = date("Y-m-d", strtotime($fdate) ); + } + + else + { + $fromdate =''; + + } + + $tdate = $search['tdate']; + + if($tdate != '0') + { + $todate = date("Y-m-d", strtotime($tdate) ); + } + + else + { + $todate = ''; + } + //echo $todate;die(); + + $finyear = $search['year']; + +$pieces = explode("-", $finyear);///fin year +//print_r($search); die(); +$startyr = $pieces['0']; +$endyr = $pieces['1']; + +//echo $endyr;die(); + + +$subquery="SELECT + DISTINCT(p.MaterialCode) AS ProductID,Ref_No,Date(CreatedOn) as Cdate,mm.MaterialName,stock,MaterialType,Category,stockdate,p.Transaction_type,Ref_Type, Ref_No,ip.product_name,invoice_number, + SUM(IF(p.Transaction_type='Add',Quantity,0)) AS Addition, + SUM(IF(p.Transaction_type='Reduce',Quantity,0)) AS Reduce, + SUM((IF(p.Transaction_type='Add',Quantity,0))-(IF(p.Transaction_type='Reduce',Quantity,0))) AS AvailableStock +FROM + T_Material_stock_history AS p +left join T_MaterialMaster mm on mm.MaterialCode = p.MaterialCode +left join ip_products ip on ip.product_id=p.MaterialCode +left join ip_invoices inv on inv.invoice_id=p.Ref_No +where p.MaterialCode='".$search['materialcode']."' + "; + + + + +if($search['month']=='' && $startyr =='' && $endyr =='') +{ + + if($fromdate != '') + { + + //echo "sv";die(); + + $subquery.=" and date(p.CreatedOn)>= '".$fromdate."'"; + } + + if($todate != '') + { + //$subquery. = " and date(p.CreatedOn)<='".$todate."'"; + + $subquery.=" and date(p.CreatedOn)<= '".$todate."'"; + } + +} + +else +{ + + if($search['month']!='') + { + $subquery.=" and month(p.CreatedOn)>= '".$search['month']."'"; + } + + if($startyr !='' && $endyr !='') + { + $subquery.=" and date(p.CreatedOn)>= '".$startyr."-04-01' and date(p.CreatedOn)<= '".$endyr."-03-31'"; + } + +} + + + + +$subquery.=" GROUP BY p.CreatedOn"; +//$subquery. = "GROUP BY p.MaterialCode"; + +$query = $this->db->query($subquery,array()); +//print_r($this->db->last_query());die(); + + return $query->result(); + + + } + + + + public function GetMaterialCode($itemproductid) + { + $this->db->select('MaterialCode'); + $this->db->from('ip_products'); + $this->db->where('product_id',$itemproductid); + $query = $this->db->get(); + // print_r( $this->db->last_query()); + return $query->result(); + + } + + + public function Delete_ProductBatchCard($FPId) + { + + $this->db->where('FPId', $FPId); + $this->db->delete('T_FinalProduct_ConsumableMaterials'); + + + $this->db->where('FPId', $FPId); + $this->db->delete('T_FinalProduct_CoProduct_Materials'); + + $this->db->where('RefID', $FPId); + $this->db->delete('T_FinalProduct_History'); + + + $this->db->where('FPId', $FPId); + $this->db->delete('T_FinalProduct_Master'); + + + + $this->db->where('FPId', $FPId); + $this->db->delete('T_FinalProduct_PackingMaterials'); + + + $this->db->where('FPId', $FPId); + $this->db->delete('T_FinalProduct_RawMaterials'); + + $this->db->where('Ref_No', $FPId); + $this->db->delete('T_Material_stock_history'); + + return true; + + + } + + + +} + ?> \ No newline at end of file diff --git a/application/models/configmodel.php b/application/models/configmodel.php index 25e86428..61e7afc6 100644 --- a/application/models/configmodel.php +++ b/application/models/configmodel.php @@ -1,194 +1,194 @@ -db->select('Config.Config_ID, Config.ConfigName ,Config.Comments,Config.CreatedDate'); - $this->db->from('T_ConfigMaster as Config'); - // $this->db->join('t_configdetails as Con','Con.Config_ID=Config.Config_ID'); - $this->db->order_by('Config.CreatedDate','desc'); - //$this->db->order_by('hourlyid','desc'); - - $query = $this->db->get(); - $result = $query->result(); - - return $result; - } - /** - * This function used to get user information by id - * @param number $userId : This is user id - * @return array $result : This is user information - */ - -function addconfigmaster($config) - { - $this->db->trans_start(); - $this->db->insert('T_ConfigMaster', $config); - - $insert_id = $this->db->affected_rows(); - - $this->db->trans_complete(); - - //return $insert_id; - $sql='SELECT Config_ID as Config_ID FROM T_ConfigMaster Order by CreatedDate desc limit 1'; - $res = $this->db->query($sql); - return $res->result_array(); - } - - - function addconfigdetails($configvalue) - { - //print_r($configvalue); - // $this->db->trans_start(); - $this->db->insert('T_ConfigDetails', $configvalue); - - $insert_id = $this->db->affected_rows(); - - // $this->db->trans_complete(); - // print_r( $this->db->last_query()); - //print_r ($insert_id);die(); - return $insert_id; - } - - - - - - - - - /* This function used to Department list which is not available in the Costcenter master - * @param number $CostCenterCode : CostCenterCode as Parameter - * @return array $result : This is user information - */ - function GetBudgetTypeNotinCostCenter($CostCenterCode,$ConfigID) - { - - $subQuery = 'select ConfigValue from T_ConfigDetails Bud where ConfigValue not in - (select BudgetType from T_CostCenter_Budget where CostCenterCode=? and BudgetYear=(select max(BudgetYear) from T_CostCenter_Budget)) and Config_ID=?'; - - $query = $this->db->query($subQuery, array($CostCenterCode,$ConfigID)); - - // print_r($this->db->last_query()); - - return $query->result(); - } - - function GetConfigCenterMaster($ConfigID='') - { - //echo $ConfigID ;die(); - $this->db->select('*' ); - $this->db->from('T_ConfigMaster '); - //$this->db->join('T_ConfigDetails con','con.Config_ID = COM.Config_ID','left'); - $this->db->where('Config_ID', $ConfigID); - - - $query = $this->db->get(); - - return $query->result(); - } - - function GetConfigCenterDetails($ConfigID='') - { - //echo $ConfigID ;die(); - $this->db->select('*' ); - $this->db->from('T_ConfigMaster COM'); - $this->db->join('T_ConfigDetails con','con.Config_ID = COM.Config_ID','left'); - - $this->db->where('COM.Config_ID', $ConfigID); - $query = $this->db->get(); - - return $query->result(); - } - - - function updateconfig($config,$Configid) - { - $this->db->where('Config_ID', $Configid); - - $this->db->update('T_ConfigMaster', $config); - - return TRUE; - } - function updateconfigvalue($configval,$Key) - { - $this->db->where('Key', $Key); - - $this->db->update('T_ConfigDetails', $configval); - - return TRUE; - } - - - function EditBudget($Budget) - { - $this->db->trans_start(); - $this->db->insert('T_CostCenter_Budget', $Budget); - - $insert_id = $this->db->affected_rows(); - - $this->db->trans_complete(); - // print_r( $this->db->last_query()); - return $insert_id; - } - - function DeleteBudget($BudgetType='',$BudgetYear='',$CostCenterCode ='') - { - $this->db->where("BudgetType", $BudgetType); - $this->db->where("BudgetYear", $BudgetYear); - $this->db->where("CostCenterCode", $CostCenterCode); - $this->db->delete('T_CostCenter_Budget'); - //print_r( $this->db->last_query()); - } - - function DeleteDepartment($DepCode='',$CostCode='') - { - $this->db->where("DEPCode", $DepCode); - $this->db->where("CostCenterCode", $CostCode); - $this->db->delete('T_CostCenter_Departments'); - //print_r( $this->db->last_query()); - } - - function checkDeptCostExists($DepCode='',$CostCode='') - { - $this->db->select('CostCenterCode,DEPCode'); - $this->db->from('T_CostCenter_Departments'); - $this->db->where('DEPCode',$DepCode); - $this->db->where('CostCenterCode',$CostCode); - - $query = $this->db->get(); - - if ($query->num_rows > 0) { - return $query->result_array(); - } - } - - - /** - * This function is used to get the Config value from configuration table - * @return array $result : This is result of the query - */ - function getConfigValue($ConfigID ) - { - - $this->db->select('ConfigValue'); - $this->db->from('T_ConfigDetails'); - $this->db->where('Config_id ',$ConfigID ); - $query = $this->db->get(); - - return $query->result(); - } - - -} +db->select('Config.Config_ID, Config.ConfigName ,Config.Comments,Config.CreatedDate'); + $this->db->from('T_ConfigMaster as Config'); + // $this->db->join('t_configdetails as Con','Con.Config_ID=Config.Config_ID'); + $this->db->order_by('Config.CreatedDate','desc'); + //$this->db->order_by('hourlyid','desc'); + + $query = $this->db->get(); + $result = $query->result(); + + return $result; + } + /** + * This function used to get user information by id + * @param number $userId : This is user id + * @return array $result : This is user information + */ + +function addconfigmaster($config) + { + $this->db->trans_start(); + $this->db->insert('T_ConfigMaster', $config); + + $insert_id = $this->db->affected_rows(); + + $this->db->trans_complete(); + + //return $insert_id; + $sql='SELECT Config_ID as Config_ID FROM T_ConfigMaster Order by CreatedDate desc limit 1'; + $res = $this->db->query($sql); + return $res->result_array(); + } + + + function addconfigdetails($configvalue) + { + //print_r($configvalue); + // $this->db->trans_start(); + $this->db->insert('T_ConfigDetails', $configvalue); + + $insert_id = $this->db->affected_rows(); + + // $this->db->trans_complete(); + // print_r( $this->db->last_query()); + //print_r ($insert_id);die(); + return $insert_id; + } + + + + + + + + + /* This function used to Department list which is not available in the Costcenter master + * @param number $CostCenterCode : CostCenterCode as Parameter + * @return array $result : This is user information + */ + function GetBudgetTypeNotinCostCenter($CostCenterCode,$ConfigID) + { + + $subQuery = 'select ConfigValue from T_ConfigDetails Bud where ConfigValue not in + (select BudgetType from T_CostCenter_Budget where CostCenterCode=? and BudgetYear=(select max(BudgetYear) from T_CostCenter_Budget)) and Config_ID=?'; + + $query = $this->db->query($subQuery, array($CostCenterCode,$ConfigID)); + + // print_r($this->db->last_query()); + + return $query->result(); + } + + function GetConfigCenterMaster($ConfigID='') + { + //echo $ConfigID ;die(); + $this->db->select('*' ); + $this->db->from('T_ConfigMaster '); + //$this->db->join('T_ConfigDetails con','con.Config_ID = COM.Config_ID','left'); + $this->db->where('Config_ID', $ConfigID); + + + $query = $this->db->get(); + + return $query->result(); + } + + function GetConfigCenterDetails($ConfigID='') + { + //echo $ConfigID ;die(); + $this->db->select('*' ); + $this->db->from('T_ConfigMaster COM'); + $this->db->join('T_ConfigDetails con','con.Config_ID = COM.Config_ID','left'); + + $this->db->where('COM.Config_ID', $ConfigID); + $query = $this->db->get(); + + return $query->result(); + } + + + function updateconfig($config,$Configid) + { + $this->db->where('Config_ID', $Configid); + + $this->db->update('T_ConfigMaster', $config); + + return TRUE; + } + function updateconfigvalue($configval,$Key) + { + $this->db->where('Key', $Key); + + $this->db->update('T_ConfigDetails', $configval); + + return TRUE; + } + + + function EditBudget($Budget) + { + $this->db->trans_start(); + $this->db->insert('T_CostCenter_Budget', $Budget); + + $insert_id = $this->db->affected_rows(); + + $this->db->trans_complete(); + // print_r( $this->db->last_query()); + return $insert_id; + } + + function DeleteBudget($BudgetType='',$BudgetYear='',$CostCenterCode ='') + { + $this->db->where("BudgetType", $BudgetType); + $this->db->where("BudgetYear", $BudgetYear); + $this->db->where("CostCenterCode", $CostCenterCode); + $this->db->delete('T_CostCenter_Budget'); + //print_r( $this->db->last_query()); + } + + function DeleteDepartment($DepCode='',$CostCode='') + { + $this->db->where("DEPCode", $DepCode); + $this->db->where("CostCenterCode", $CostCode); + $this->db->delete('T_CostCenter_Departments'); + //print_r( $this->db->last_query()); + } + + function checkDeptCostExists($DepCode='',$CostCode='') + { + $this->db->select('CostCenterCode,DEPCode'); + $this->db->from('T_CostCenter_Departments'); + $this->db->where('DEPCode',$DepCode); + $this->db->where('CostCenterCode',$CostCode); + + $query = $this->db->get(); + + if ($query->num_rows > 0) { + return $query->result_array(); + } + } + + + /** + * This function is used to get the Config value from configuration table + * @return array $result : This is result of the query + */ + function getConfigValue($ConfigID ) + { + + $this->db->select('ConfigValue'); + $this->db->from('T_ConfigDetails'); + $this->db->where('Config_id ',$ConfigID ); + $query = $this->db->get(); + + return $query->result(); + } + + +} ?> \ No newline at end of file diff --git a/application/models/dahsboard_model.php b/application/models/dahsboard_model.php index f1d8c4cf..184afd94 100644 --- a/application/models/dahsboard_model.php +++ b/application/models/dahsboard_model.php @@ -1772,10 +1772,10 @@ if ($cname!= ''){ } - $sql.=" group by pono,igrn"; + $sql.="group by pono,igrn"; // echo $m; // echo $sid; -// echo $sql;exit; +//echo $sql; $query = $this->db->query($sql); $filequery = $query->result(); diff --git a/application/models/inwardgateregister_model.php b/application/models/inwardgateregister_model.php index 7453b507..f1fa6acb 100644 --- a/application/models/inwardgateregister_model.php +++ b/application/models/inwardgateregister_model.php @@ -1,859 +1,859 @@ -db->set('FilePath', $Picture); //value that used to update column -$this->db->where('BillNo', $bill); //which row want to upgrade -$this->db->update('T_Inwardgateregister_fileupload'); -$afftectedRows = $this->db->affected_rows(); -return $afftectedRows; - -} - - - function getfies($igr) - { - - $this->db->select('*'); - - - $this->db->from('T_Inwardgateregister_fileupload'); - - $this->db->where('IGRNO',$igr); - - $query = $this->db->get(); - - return $query->result(); - } - - function fileupload($myfiles) - { - - - $this->db->insert('T_Inwardgateregister_fileupload',$myfiles); - $myfile=$this->db->affected_rows(); - return $myfile; - } - - - /*------------------------------------------------------------*/ - function addMaterialStockHistory($MaterialstockHistoryadd) -{ - - $this->db->trans_start(); - $this->db->insert('T_Material_stock_history', $MaterialstockHistoryadd); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - //print_r($insert_id); - if($insert_id>0) - { - $subQuery = 'select * from T_Material_stock_history'; - - $query = $this->db->query($subQuery); - - return $query->result(); - } - - -} - -/*------------------------------------------------------------*/ - // function igrListing() - // { - // $this->db->select('igr.*,PO.DeliveryDate,sup.SupplierName,igr.file'); - // $this->db->from('T_IGR_Master igr'); - // $this->db->join('T_PurchaseOrder_Master PO','igr.PONO = PO.PONO'); - // $this->db->join('T_SupplierDetailsN` sup','PO.SupplierID = sup.SupplierID'); - // $this->db->order_by('igr.CreatedDate','desc'); - // $query = $this->db->get(); - // $result = $query->result(); - // return $result; - // } - function igrListing() - { - $this->db->select('igr.*,PO.DeliveryDate,sup.SupplierName,fileup.FilePath,igr.file'); - $this->db->from('T_IGR_Master igr'); - $this->db->join('T_PurchaseOrder_Master PO','igr.PONO = PO.PONO'); - $this->db->join('T_Inwardgateregister_fileupload fileup',' igr.IGRNO = fileup.IGRNO','left'); - $this->db->join('T_SupplierDetailsN` sup','PO.SupplierID = sup.SupplierID'); - $this->db->group_by('igr.IGRNO','desc'); - $query = $this->db->get(); - $result = $query->result(); - return $result; - } - - - - function viewIGRFile($IGRNO) - { - $this->db->distinct(); - $this->db->select('*'); //BillNo,IGRNO,FilePath,PONO - $this->db->from('T_Inwardgateregister_fileupload'); - $this->db->where('IGRNO',$IGRNO); - - $query = $this->db->get(); - - $result = $query->result(); - // print_r($result);die; - //print_r($this->db->last_query()); - return $result; - - - - } - - function viewIGRFile1($IGRNO) - { - $this->db->distinct(); - $this->db->select('igrm.file,igrm.PONO as pono'); //BillNo,IGRNO,FilePath,PONO - $this->db->from('T_IGR_Master igrm'); - //$this->db->join('T_Inwardgateregister_fileupload igrf','igrm.IGRNO = igrf.IGRNO','left'); - //$this->db->join('T_IGR_Details igrd','igrm.IGRNO = igrd.IGRNO','left'); - - $this->db->where('igrm.IGRNO',$IGRNO); - - $query = $this->db->get(); - - $result = $query->result(); - // print_r($result);die; - //print_r($this->db->last_query()); - return $result; - - - - } - - function getpurchaseorder() - { - $this->db->distinct(); - $this->db->select('POM.PONO,POM.ServiceDescription,POM.DeliveryDate,sup.SupplierName,sup.Address,POM.status,OGR_Status'); - $this->db->from('T_PurchaseOrder_Master POM'); - $this->db->join('T_PurchaseOrder_LineItem POL', 'POL.PONO = POM.PONO'); - $this->db->join('T_SupplierDetailsN sup', 'POM.SupplierID = sup.SupplierID'); - $this->db->join('T_OGR_Master OGM ', 'POM.PONO = OGM.PONO_INV','left'); - $this->db->where('POM.Status',PO_RELEASED); - $this->db->where('POM.POType !=',SERVICE); - // $this->db->or_where('POM.Status',IGR_CREATED); - $this->db->or_where('POM.Status',MRIR_CREATED); - $this->db->or_where('POM.Status',MRIR_APPROVED); - $this->db->or_where('POM.Status',OGR_COMPLETE); - $query = $this->db->get(); - - $result = $query->result(); - //print_r($this->db->last_query()); - return $result; - } - - - function viewpurchaseorder($PO) - { - - $subQuery ='SELECT distinct POM.PONO,POL.MaterialCode,POL.Quantity,POL.ReceivedQuantity,(POL.Quantity -POL.ReceivedQuantity ) as PendingQty,QuantityRejected,POL.PONO,MM.MaterialName,MM.UOM - from T_PurchaseOrder_Master POM - left join T_PurchaseOrder_LineItem POL on POL.PONO = POM.PONO - left join T_IGR_Master IGM on IGM.PONO =POL.PONO - left join T_IGR_Details igr on igr.MaterialCode = POL.MaterialCode and IGM.PONO =POL.PONO - left join T_MaterialMaster MM on MM.MaterialCode = POL.MaterialCode - left join T_MRIR_Master MRM on POM.PONO=MRM.PONO - left join T_MRIR_Details MRD on MRM.MRIRNO=MRD.MRIRNO and POL.MaterialCode=MRD.MaterialCode - where POM.PONO=? group by POL.MaterialCode';// and POM.Status not in(?) '; - - $query = $this->db->query($subQuery, array($PO,IGR_CREATED)); - - // print_r($this->db->last_query()); - return $query->result(); - - /* $this->db->select('POM.PONO,POL.MaterialCode,POL.Quantity,POL.PONO,MM.MaterialName,MM.UOM'); - $this->db->from('T_PurchaseOrder_Master POM'); - $this->db->join('T_PurchaseOrder_LineItem POL', 'POL.PONO = POM.PONO','left'); - $this->db->join('T_MaterialMaster MM', 'MM.MaterialCode = POL.MaterialCode','left'); - $this->db->where('POM.PONO',$PO ); - - $this->db->where('POL.Status !=',POLINEITEM_IGR_CREATED ); - $query = $this->db->get(); - - $result = $query->result(); - - $this->db->last_query(); - return $result; */ - } - - function addigrM($igrM) - { - - $this->db->trans_start(); - $this->db->insert('T_IGR_Master', $igrM); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - //print_r($insert_id); - if($insert_id>0) - { - $subQuery = 'select IGRNO from T_IGR_Master Order by CreatedDate desc limit 1'; - - $query = $this->db->query($subQuery); - - return $query->result(); - } - } - - function addigrD($igrD) - { - $this->db->trans_start(); - $this->db->insert('T_IGR_Details', $igrD); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - - if($insert_id>0) - { - // $subQuery = 'select max(IGRItemNo) as IGRItemNo from T_IGR_Details'; - $subQuery = 'select IGRItemNo as IGRItemNo from T_IGR_Details Order by CreatedDate desc limit 1'; - - $query = $this->db->query($subQuery); - - //print_r($query); - - - return $query->result(); - } - } - - - - function addmaterialhistory($historydetails) - { - - $this->db->trans_start(); - $this->db->insert('T_Material_stock_history', $historydetails); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return true; - } - - - - function addmaterialmaster($current_qty,$MaterialCode) - { - $this->db->where('MaterialCode',$MaterialCode); - $this->db->update('T_MaterialMaster',$current_qty); - return TRUE; - } - - - function get_CurrentQty($MaterialCode) - { - $this->db->select('Current_stock'); - $this->db->from('T_MaterialMaster'); - $this->db->where('T_MaterialMaster.MaterialCode',$MaterialCode); - $query = $this->db->get(); - // print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - - function getitemvalue($pono,$MaterialCode) - { - $this->db->select('Rate,SupplierID'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO'); - $this->db->where('T_PurchaseOrder_LineItem.PONO',$pono); - $this->db->where('MaterialCode',$MaterialCode); - $query = $this->db->get(); - $result = $query->result(); - return $result; - - } - - - function viewigr($IGRNO) - { - $this->db->distinct(); - $this->db->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity'); - $this->db->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity'); - $this->db->from('T_IGR_Master igr'); - $this->db->join('T_IGR_Details igrd','igrd.IGRNO = igr.IGRNO'); - $this->db->join('T_PurchaseOrder_Master POM','igr.PONO = POM.PONO'); - $this->db->join('T_PurchaseOrder_LineItem POL','igr.PONO = POL.PONO and POL.MaterialCode=igrd.MaterialCode '); - $this->db->join('T_SupplierDetailsN sup', 'sup.SupplierID = POM.SupplierID'); - $this->db->join('T_MaterialMaster MM', 'MM.MaterialCode = igrd.MaterialCode'); - $this->db->where('igr.IGRNO',$IGRNO); - - - $query = $this->db->get(); - // print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - function UpdatePOLineItem($LineItem,$PONO,$MaterialCode) - { - $this->db->where('PONO', $PONO); - $this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_PurchaseOrder_LineItem', $LineItem); - - return TRUE; - } - - - function UpdateMRIROUTQty($mrirarray,$MRIRNO,$MaterialCode) - { - - $this->db->where('MRIRNO', $MRIRNO); - $this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_MRIR_Details', $mrirarray); - - return TRUE; - } - - - function UpdatePOMasterOGRStatus($pono,$POMasterStatuss) - { - $this->db->where('PONO', $pono); - $this->db->update('T_PurchaseOrder_Master', $POMasterStatuss); - return TRUE; - } - - - function update_OGR($PONO,$status) - { - $this->db->select('*'); - $this->db->from('T_OGR_Master'); - $this->db->where('PONO_INV',$PONO); - $query= $this->db->get(); - - if($query->num_rows!=0) - { - $this->db->where('PONO_INV',$PONO); - $ogrstatus=array('Status'=>$status); - $this->db->update('T_OGR_Master',$ogrstatus); - } - } - - function UpdatePOMaster($PONO,$updatedBy) - { - $this->db->select('*'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO',$PONO); - $this->db->where('Status !=',IGR_CREATED); - - $query = $this->db->get(); - - - if ($query->num_rows == 0) { - $this->db->where('PONO', $PONO); - $POStatus = array('status'=>IGR_CREATED,'UpdateBY'=>$updatedBy); - $this->db->update('T_PurchaseOrder_Master', $POStatus); - } - - } - - function UpdateOGRMasterOGRStatus($OGRNO) - { - $this->db->select('*'); - $this->db->from('T_OGR_Details'); - $this->db->where('OGRNO',$OGRNO); - $this->db->where('Status !=',OGR_PARTIAL_COMPLETE); - - $query = $this->db->get(); - - if ($query->num_rows == 0) { - $this->db->where('OGRNO', $OGRNO); - $OGRStatus = array('status'=>OGR_PARTIAL_COMPLETE); - $this->db->update('T_OGR_Master', $OGRStatus); - } - - else - { - $this->db->where('OGRNO', $OGRNO); - $OGRStatus = array('status'=>OGR_COMPLETE); - $this->db->update('T_OGR_Master', $OGRStatus); - } - } - - - - function UpdateMRIRMasterOGRStatus($MRIRNO,$OGRNO) - { - $this->db->select('*'); - $this->db->from('T_OGR_Details'); - $this->db->where('OGRNO',$OGRNO); - $this->db->where('Status !=',OGR_PARTIAL_COMPLETE); - - $query = $this->db->get(); - - if ($query->num_rows == 0) { - $this->db->where('MRIRNO', $MRIRNO); - $OGRStatus = array('OGRstatus'=>OGR_PARTIAL_COMPLETE); - $this->db->update('T_MRIR_Master', $OGRStatus); - } - - else - { - $this->db->where('MRIRNO', $MRIRNO); - $OGRStatus = array('OGRstatus'=>OGR_COMPLETE); - $this->db->update('T_MRIR_Master', $OGRStatus); - } - } - - - - function updateogrpomaster($pono) - { - $this->db->select('*'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO',$pono); - $this->db->where('OGR_Status !=','ST064'); - - $query = $this->db->get(); - - - if ($query->num_rows == 0) { - $this->db->where('PONO',$pono); - $POStatus = array('status'=>'ST063'); - $this->db->update('T_PurchaseOrder_Master', $POStatus); - } - } - - - - function getPOLineItemReceivedQty($PONO,$MaterialCode) - { - $this->db->select('ReceivedQuantity'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO',$PONO); - $this->db->where('MaterialCode',$MaterialCode); - $query = $this->db->get(); - // print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - - function GetMRIROutQty($MRIRNO,$MaterialCode) - { - $this->db->select('Ogr_Out_Qty'); - $this->db->from('T_MRIR_Details'); - $this->db->where('MRIRNO',$MRIRNO); - $this->db->where('MaterialCode',$MaterialCode); - $query = $this->db->get(); - // print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - - function getCustomer() - { - $subQuery='select client_id,client_name from ip_clients'; - $query = $this->db->query($subQuery); - //print_r( $this->db->last_query()); - return $query->result(); - - } - - - function getSupplier() - { - $subQuery='select SupplierID,SupplierName from T_SupplierDetailsN'; - $query = $this->db->query($subQuery); - //print_r( $this->db->last_query()); - return $query->result(); - - } - - - function getstoredmaterialcode() - { - $subQuery='select MaterialCode,MaterialName from T_MaterialMaster'; - $query = $this->db->query($subQuery); - return $query->result(); - } - - - - function getOGRData() - { - $this->db->select('T_OGR_Master.*,T_OGR_Details.*,T_SupplierDetailsN.SupplierName,sup.SupplierName as Servicesupplier'); - $this->db->from('T_OGR_Master'); - $this->db->join('T_OGR_Details','T_OGR_Details.OGRNO=T_OGR_Master.OGRNO'); - $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV','left'); - $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_PurchaseOrder_Master.SupplierID','left'); - $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=T_OGR_Details.SupplierID','left'); - $this->db->group_by('T_OGR_Master.OGRNO'); - //$this->db->where(); - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - - function getOGRDataforedit($OGRNO) - { - $this->db->select('T_OGR_Master.*,T_SupplierDetailsN.SupplierName,T_OGR_Details.*,sup.SupplierName as ServiceSupname,T_MaterialMaster.MaterialName as Matname,Remark'); - $this->db->from('T_OGR_Master'); - $this->db->join('T_OGR_Details','T_OGR_Details.OGRNO=T_OGR_Master.OGRNO'); - $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV','left'); - $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_PurchaseOrder_Master.SupplierID','left'); - $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=T_OGR_Details.SupplierID','left'); - - $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_OGR_Details.MaterialCode','left'); - $this->db->where('T_OGR_Master.OGRNO',$OGRNO); - //$this->db->group_by('T_OGR_Master.OGRNO'); - - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - - - function getOGRlineDataforedit($OGRNO,$MRIRNO) - { - $this->db->select('T_OGR_Details.*,MaterialName,ActualQuantityReceived,Quantity,QuantityRejected'); - $this->db->from('T_OGR_Details'); - $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_OGR_Details.MaterialCode'); - $this->db->join('T_OGR_Master','T_OGR_Master.OGRNO=T_OGR_Details.OGRNO'); - $this->db->join('T_MRIR_Master','T_MRIR_Master.PONO=T_OGR_Master.PONO_INV','left'); - $this->db->join('T_MRIR_Details','T_MRIR_Details.MRIRNO=T_MRIR_Master.MRIRNO and T_MRIR_Details.MaterialCode=T_OGR_Details.MaterialCode'); - $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_MRIR_Master.PONO'); - $this->db->join('T_PurchaseOrder_LineItem','T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO and T_OGR_Details.MaterialCode=T_PurchaseOrder_LineItem.MaterialCode'); - $this->db->where('T_OGR_Details.OGRNO',$OGRNO); - $this->db->where('T_MRIR_Details.MRIRNO',$MRIRNO); - $this->db->group_by('T_OGR_Details.MaterialCode'); - - $query = $this->db->get(); - // print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - function getInvoice($CustomerId) - { - - $this->db->select('ip_invoices.invoice_id,invoice_number,item_product_id,item_name,item_quantity'); - $this->db->from('ip_invoices'); - $this->db->join('ip_invoice_items','ip_invoice_items.invoice_id = ip_invoices.invoice_id'); - $this->db->join('ip_clients','ip_invoices.client_id = ip_clients.client_id'); - - $this->db->where('ip_invoices.client_id',$CustomerId); - - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - - function getPOmrir($PONO) - { - $this->db->select('MRIRNO'); - $this->db->from('T_MRIR_Master'); - $this->db->where('T_MRIR_Master.PONO',$PONO); - $this->db->where('T_MRIR_Master.OGRstatus !=',OGR_COMPLETE); - // $this->db->where('Status !=',IGR_CREATED); - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - - } - - - - - function getPO($supplierId) - { - - /// echo $supplierId; - $subQuery='select T_PurchaseOrder_Master.PONO from T_PurchaseOrder_Master - join T_MRIR_Master on T_MRIR_Master.PONO= T_PurchaseOrder_Master.PONO - where T_PurchaseOrder_Master.SupplierID=? and (T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=?) group by T_PurchaseOrder_Master.PONO'; - - //$query= $this->db->query($subQuery, array($supplierId,ST044,PO,ST063)); - $query= $this->db->query($subQuery, array($supplierId,ST044,PO,PO_RELEASED,IGR_CREATED,MRIR_CREATED,PARTIAL_MRIRAPPROVED,OGR_COMPLETE,OGR_PARTIAL_COMPLETE,OGR_CREATED)); - //print_r( $this->db->last_query()); - return $query->result(); - - - } - - function getPODetails($PONO) - { - - $subQuery ='select distinct T_PurchaseOrder_Master.PONO,T_PurchaseOrder_LineItem.MaterialCode, -T_PurchaseOrder_LineItem.Quantity as Oqty,T_MRIR_Details.ActualQuantityReceived, -T_MRIR_Details.QuantityRejected,MaterialName,balance_Qty -from T_PurchaseOrder_Master -join T_PurchaseOrder_LineItem on T_PurchaseOrder_LineItem.PONO = T_PurchaseOrder_Master.PONO -join T_MRIR_Master on T_MRIR_Master.PONO = T_PurchaseOrder_Master.PONO -join T_MRIR_Details on T_MRIR_Master.MRIRNO = T_MRIR_Details.MRIRNO and T_PurchaseOrder_LineItem.MaterialCode=T_MRIR_Details.MaterialCode -join T_MaterialMaster on T_MRIR_Details.MaterialCode=T_MaterialMaster.MaterialCode -left join T_OGR_Master on T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV -left join T_OGR_Details on T_OGR_Master.OGRNO=T_OGR_Details.OGRNO and T_PurchaseOrder_LineItem.MaterialCode= T_OGR_Details.MaterialCode -where T_PurchaseOrder_Master.PONO=?'; - - $query = $this->db->query($subQuery, array($PONO)); - //print_r($this->db->last_query()); - return $query->result(); - - - } - - - - function getPOMRIRDetails($MRIRno,$PONO,$materialcode) - { - $subQuery='select T_MRIR_Details.MaterialCode,ActualQuantityReceived,QuantityAccepted,QuantityRejected, -MaterialName,Quantity as Oqty,SUM(Ogr_Out_Qty) as allowedQty -from T_MRIR_Details -join T_MaterialMaster on T_MRIR_Details.MaterialCode=T_MaterialMaster.MaterialCode -join T_MRIR_Master on T_MRIR_Details.MRIRNO = T_MRIR_Master.MRIRNO -join T_PurchaseOrder_LineItem on T_MRIR_Master.PONO = T_PurchaseOrder_LineItem.PONO and T_PurchaseOrder_LineItem.MaterialCode=T_MRIR_Details.MaterialCode -where T_MRIR_Details.MRIRNO=? and T_MRIR_Master.PONO=? and T_MRIR_Details.MaterialCode=? group by T_MRIR_Details.MaterialCode;'; - $query = $this->db->query($subQuery, array($MRIRno,$PONO,$materialcode)); - //print_r($this->db->last_query()); - return $query->result(); - - - } - - - function getPOMRIRMaterial($MRIRno,$PONO) - { - $this->db->select('MaterialCode'); - $this->db->from('T_MRIR_Details'); - $this->db->join('T_MRIR_Master','T_MRIR_Master.MRIRNO=T_MRIR_Details.MRIRNO'); - $this->db->where('T_MRIR_Details.MRIRNO',$MRIRno); - $this->db->where('PONO',$PONO); - $this->db->group_by('T_MRIR_Details.MaterialCode'); - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - - } - - - function gettotalout($PONO,$materialcode) - { - $subQuery='select SUM(Ogr_Out_Qty) -from T_MRIR_Details -join T_MRIR_Master on T_MRIR_Master.MRIRNO= T_MRIR_Details.MRIRNO -where PONO =? and MaterialCode = ?; '; - -$query = $this->db->query($subQuery, array($PONO,$materialcode)); - //print_r($this->db->last_query()); - return $query->result(); - } - - - - - - - - function getPOmaterialDetails($PONO,$materialcode) - { - $subQuery='select distinct T_PurchaseOrder_LineItem.MaterialCode,MaterialName,T_PurchaseOrder_LineItem.Quantity as Oqty,T_MRIR_Details.ActualQuantityReceived,T_MRIR_Details.QuantityRejected,balance_Qty - from T_PurchaseOrder_Master -join T_PurchaseOrder_LineItem on T_PurchaseOrder_LineItem.PONO = T_PurchaseOrder_Master.PONO -join T_MRIR_Master on T_MRIR_Master.PONO = T_PurchaseOrder_Master.PONO -join T_MRIR_Details on T_MRIR_Master.MRIRNO = T_MRIR_Details.MRIRNO and T_PurchaseOrder_LineItem.MaterialCode=T_MRIR_Details.MaterialCode -join T_MaterialMaster on T_MRIR_Details.MaterialCode=T_MaterialMaster.MaterialCode -left join T_OGR_Master on T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV -left join T_OGR_Details on T_OGR_Master.OGRNO=T_OGR_Details.OGRNO and T_PurchaseOrder_LineItem.MaterialCode= T_OGR_Details.MaterialCode -where T_PurchaseOrder_LineItem.PONO=? and T_PurchaseOrder_LineItem.MaterialCode=?' -; -$query = $this->db->query($subQuery, array($PONO,$materialcode)); - // print_r($this->db->last_query()); - return $query->result(); - } - - -function getPOmaterial($PONO) -{ - $subQuery ='select MaterialCode from T_PurchaseOrder_LineItem where PONO=?'; - - $query = $this->db->query($subQuery, array($PONO)); - //print_r($this->db->last_query()); - return $query->result(); -} - - - - function AddOGR($ogrmaster) - { - $this->db->trans_start(); - $this->db->insert('T_OGR_Master', $ogrmaster); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - //print_r($insert_id); - if($insert_id>0) - { - //$subQuery = 'select max(OGRNO) as OGRNO from T_OGR_Master'; - $subQuery = 'select OGRNO from T_OGR_Master order by CreatedOn desc limit 1'; - - $query = $this->db->query($subQuery); - - return $query->result(); - } - } - - - - - function getlastogrline() - { - // $subQuery = 'select max(OGRItemNO) as OGRItemNO from T_OGR_Details'; - $subQuery = 'select OGRItemNO from T_OGR_Details order by CreatedOn desc limit 1'; - - $query = $this->db->query($subQuery); - - return $query->result(); - } - - - function UpdateOGR($updateogrmaster,$OGRNO) - { - $this->db->where('OGRNO',$OGRNO); - //$this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_OGR_Master', $updateogrmaster); - - return TRUE; - } - - - function AddOgrLine($Ogrline) - { - $this->db->trans_start(); - $this->db->insert('T_OGR_Details',$Ogrline); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; - } - - - // function GetIGR_Details($pono) - // { - // $this->db->select('IGRNO,MRIRNO,MaterialCode,'); - // $this->db->from('ip_invoices'); - // $this->db->join('ip_invoice_items','ip_invoice_items.invoice_id = ip_invoices.invoice_id'); - // $this->db->join('ip_clients','ip_invoices.client_id = ip_clients.client_id'); - - // $this->db->where('ip_invoices.client_id',$CustomerId); - - // $query = $this->db->get(); - // //print_r( $this->db->last_query()); - // $result = $query->result(); - // return $result; - // } - - - - - function GetPreSavedQty($pono,$MaterialCode) - { - // $subQuery = 'select Total_OutwardQty from T_PurchaseOrder_LineItem where PONO=? and MaterialCode=?'; - // $query = $this->db->query($subQuery, array($pono,$MaterialCode)); - // //print_r($this->db->last_query()); - // return $query->result(); - - - $this->db->select('Total_OutwardQty'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO',$pono); - $this->db->where('MaterialCode',$MaterialCode); - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - - } - - - function check_PO($pono) - { - $subQuery='select * from T_OGR_Master where PONO_INV=?'; - $query=$this->db->query($subQuery,array($pono)); - return $query->result(); - } - - - function UpdatePOMasterOGR($postatus,$pono) - { - $this->db->where('PONO',$pono); - //$this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_PurchaseOrder_Master', $postatus); - - return TRUE; - } - - function updateigr($igrarr,$IGRNo){ - - //$this->db->where('PONO',$PONO); - $this->db->where('IGRNO',$IGRNo); - $this->db->update('T_IGR_Master',$igrarr); - $r = $this->db->affected_rows(); - return $r; - } - function getpolineqty($NewPO) -{ - $this->db->select('sum(Quantity)as Qty,sum(ReceivedQuantity)as rec'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO',$NewPO); - - $query = $this->db->get(); - return $query->result(); -} - - -function POLineItemsupdatestatus($PONO,$Newstatus) -{ - $this->db->where('PONO',$PONO); - $this->db->update('T_PurchaseOrder_LineItem',$Newstatus); - $update = $this->db->affected_rows(); - return $update; - -} - -function pomasterupdatestatus($PONO,$Newstatus) -{ - $this->db->where('PONO',$PONO); - $this->db->update('T_PurchaseOrder_Master',$Newstatus); - $update = $this->db->affected_rows(); - return $update; -} - +db->set('FilePath', $Picture); //value that used to update column +$this->db->where('BillNo', $bill); //which row want to upgrade +$this->db->update('T_Inwardgateregister_fileupload'); +$afftectedRows = $this->db->affected_rows(); +return $afftectedRows; + +} + + + function getfies($igr) + { + + $this->db->select('*'); + + + $this->db->from('T_Inwardgateregister_fileupload'); + + $this->db->where('IGRNO',$igr); + + $query = $this->db->get(); + + return $query->result(); + } + + function fileupload($myfiles) + { + + + $this->db->insert('T_Inwardgateregister_fileupload',$myfiles); + $myfile=$this->db->affected_rows(); + return $myfile; + } + + + /*------------------------------------------------------------*/ + function addMaterialStockHistory($MaterialstockHistoryadd) +{ + + $this->db->trans_start(); + $this->db->insert('T_Material_stock_history', $MaterialstockHistoryadd); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + //print_r($insert_id); + if($insert_id>0) + { + $subQuery = 'select * from T_Material_stock_history'; + + $query = $this->db->query($subQuery); + + return $query->result(); + } + + +} + +/*------------------------------------------------------------*/ + // function igrListing() + // { + // $this->db->select('igr.*,PO.DeliveryDate,sup.SupplierName,igr.file'); + // $this->db->from('T_IGR_Master igr'); + // $this->db->join('T_PurchaseOrder_Master PO','igr.PONO = PO.PONO'); + // $this->db->join('T_SupplierDetailsN` sup','PO.SupplierID = sup.SupplierID'); + // $this->db->order_by('igr.CreatedDate','desc'); + // $query = $this->db->get(); + // $result = $query->result(); + // return $result; + // } + function igrListing() + { + $this->db->select('igr.*,PO.DeliveryDate,sup.SupplierName,fileup.FilePath,igr.file'); + $this->db->from('T_IGR_Master igr'); + $this->db->join('T_PurchaseOrder_Master PO','igr.PONO = PO.PONO'); + $this->db->join('T_Inwardgateregister_fileupload fileup',' igr.IGRNO = fileup.IGRNO','left'); + $this->db->join('T_SupplierDetailsN` sup','PO.SupplierID = sup.SupplierID'); + $this->db->group_by('igr.IGRNO','desc'); + $query = $this->db->get(); + $result = $query->result(); + return $result; + } + + + + function viewIGRFile($IGRNO) + { + $this->db->distinct(); + $this->db->select('*'); //BillNo,IGRNO,FilePath,PONO + $this->db->from('T_Inwardgateregister_fileupload'); + $this->db->where('IGRNO',$IGRNO); + + $query = $this->db->get(); + + $result = $query->result(); + // print_r($result);die; + //print_r($this->db->last_query()); + return $result; + + + + } + + function viewIGRFile1($IGRNO) + { + $this->db->distinct(); + $this->db->select('igrm.file,igrm.PONO as pono'); //BillNo,IGRNO,FilePath,PONO + $this->db->from('T_IGR_Master igrm'); + //$this->db->join('T_Inwardgateregister_fileupload igrf','igrm.IGRNO = igrf.IGRNO','left'); + //$this->db->join('T_IGR_Details igrd','igrm.IGRNO = igrd.IGRNO','left'); + + $this->db->where('igrm.IGRNO',$IGRNO); + + $query = $this->db->get(); + + $result = $query->result(); + // print_r($result);die; + //print_r($this->db->last_query()); + return $result; + + + + } + + function getpurchaseorder() + { + $this->db->distinct(); + $this->db->select('POM.PONO,POM.ServiceDescription,POM.DeliveryDate,sup.SupplierName,sup.Address,POM.status,OGR_Status'); + $this->db->from('T_PurchaseOrder_Master POM'); + $this->db->join('T_PurchaseOrder_LineItem POL', 'POL.PONO = POM.PONO'); + $this->db->join('T_SupplierDetailsN sup', 'POM.SupplierID = sup.SupplierID'); + $this->db->join('T_OGR_Master OGM ', 'POM.PONO = OGM.PONO_INV','left'); + $this->db->where('POM.Status',PO_RELEASED); + $this->db->where('POM.POType !=',SERVICE); + // $this->db->or_where('POM.Status',IGR_CREATED); + $this->db->or_where('POM.Status',MRIR_CREATED); + $this->db->or_where('POM.Status',MRIR_APPROVED); + $this->db->or_where('POM.Status',OGR_COMPLETE); + $query = $this->db->get(); + + $result = $query->result(); + //print_r($this->db->last_query()); + return $result; + } + + + function viewpurchaseorder($PO) + { + + $subQuery ='SELECT distinct POM.PONO,POL.MaterialCode,POL.Quantity,POL.ReceivedQuantity,(POL.Quantity -POL.ReceivedQuantity ) as PendingQty,QuantityRejected,POL.PONO,MM.MaterialName,MM.UOM + from T_PurchaseOrder_Master POM + left join T_PurchaseOrder_LineItem POL on POL.PONO = POM.PONO + left join T_IGR_Master IGM on IGM.PONO =POL.PONO + left join T_IGR_Details igr on igr.MaterialCode = POL.MaterialCode and IGM.PONO =POL.PONO + left join T_MaterialMaster MM on MM.MaterialCode = POL.MaterialCode + left join T_MRIR_Master MRM on POM.PONO=MRM.PONO + left join T_MRIR_Details MRD on MRM.MRIRNO=MRD.MRIRNO and POL.MaterialCode=MRD.MaterialCode + where POM.PONO=? group by POL.MaterialCode';// and POM.Status not in(?) '; + + $query = $this->db->query($subQuery, array($PO,IGR_CREATED)); + + // print_r($this->db->last_query()); + return $query->result(); + + /* $this->db->select('POM.PONO,POL.MaterialCode,POL.Quantity,POL.PONO,MM.MaterialName,MM.UOM'); + $this->db->from('T_PurchaseOrder_Master POM'); + $this->db->join('T_PurchaseOrder_LineItem POL', 'POL.PONO = POM.PONO','left'); + $this->db->join('T_MaterialMaster MM', 'MM.MaterialCode = POL.MaterialCode','left'); + $this->db->where('POM.PONO',$PO ); + + $this->db->where('POL.Status !=',POLINEITEM_IGR_CREATED ); + $query = $this->db->get(); + + $result = $query->result(); + + $this->db->last_query(); + return $result; */ + } + + function addigrM($igrM) + { + + $this->db->trans_start(); + $this->db->insert('T_IGR_Master', $igrM); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + //print_r($insert_id); + if($insert_id>0) + { + $subQuery = 'select IGRNO from T_IGR_Master Order by CreatedDate desc limit 1'; + + $query = $this->db->query($subQuery); + + return $query->result(); + } + } + + function addigrD($igrD) + { + $this->db->trans_start(); + $this->db->insert('T_IGR_Details', $igrD); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + + if($insert_id>0) + { + // $subQuery = 'select max(IGRItemNo) as IGRItemNo from T_IGR_Details'; + $subQuery = 'select IGRItemNo as IGRItemNo from T_IGR_Details Order by CreatedDate desc limit 1'; + + $query = $this->db->query($subQuery); + + //print_r($query); + + + return $query->result(); + } + } + + + + function addmaterialhistory($historydetails) + { + + $this->db->trans_start(); + $this->db->insert('T_Material_stock_history', $historydetails); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return true; + } + + + + function addmaterialmaster($current_qty,$MaterialCode) + { + $this->db->where('MaterialCode',$MaterialCode); + $this->db->update('T_MaterialMaster',$current_qty); + return TRUE; + } + + + function get_CurrentQty($MaterialCode) + { + $this->db->select('Current_stock'); + $this->db->from('T_MaterialMaster'); + $this->db->where('T_MaterialMaster.MaterialCode',$MaterialCode); + $query = $this->db->get(); + // print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + + function getitemvalue($pono,$MaterialCode) + { + $this->db->select('Rate,SupplierID'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO'); + $this->db->where('T_PurchaseOrder_LineItem.PONO',$pono); + $this->db->where('MaterialCode',$MaterialCode); + $query = $this->db->get(); + $result = $query->result(); + return $result; + + } + + + function viewigr($IGRNO) + { + $this->db->distinct(); + $this->db->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity'); + $this->db->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity'); + $this->db->from('T_IGR_Master igr'); + $this->db->join('T_IGR_Details igrd','igrd.IGRNO = igr.IGRNO'); + $this->db->join('T_PurchaseOrder_Master POM','igr.PONO = POM.PONO'); + $this->db->join('T_PurchaseOrder_LineItem POL','igr.PONO = POL.PONO and POL.MaterialCode=igrd.MaterialCode '); + $this->db->join('T_SupplierDetailsN sup', 'sup.SupplierID = POM.SupplierID'); + $this->db->join('T_MaterialMaster MM', 'MM.MaterialCode = igrd.MaterialCode'); + $this->db->where('igr.IGRNO',$IGRNO); + + + $query = $this->db->get(); + // print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + function UpdatePOLineItem($LineItem,$PONO,$MaterialCode) + { + $this->db->where('PONO', $PONO); + $this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_PurchaseOrder_LineItem', $LineItem); + + return TRUE; + } + + + function UpdateMRIROUTQty($mrirarray,$MRIRNO,$MaterialCode) + { + + $this->db->where('MRIRNO', $MRIRNO); + $this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_MRIR_Details', $mrirarray); + + return TRUE; + } + + + function UpdatePOMasterOGRStatus($pono,$POMasterStatuss) + { + $this->db->where('PONO', $pono); + $this->db->update('T_PurchaseOrder_Master', $POMasterStatuss); + return TRUE; + } + + + function update_OGR($PONO,$status) + { + $this->db->select('*'); + $this->db->from('T_OGR_Master'); + $this->db->where('PONO_INV',$PONO); + $query= $this->db->get(); + + if($query->num_rows!=0) + { + $this->db->where('PONO_INV',$PONO); + $ogrstatus=array('Status'=>$status); + $this->db->update('T_OGR_Master',$ogrstatus); + } + } + + function UpdatePOMaster($PONO,$updatedBy) + { + $this->db->select('*'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO',$PONO); + $this->db->where('Status !=',IGR_CREATED); + + $query = $this->db->get(); + + + if ($query->num_rows == 0) { + $this->db->where('PONO', $PONO); + $POStatus = array('status'=>IGR_CREATED,'UpdateBY'=>$updatedBy); + $this->db->update('T_PurchaseOrder_Master', $POStatus); + } + + } + + function UpdateOGRMasterOGRStatus($OGRNO) + { + $this->db->select('*'); + $this->db->from('T_OGR_Details'); + $this->db->where('OGRNO',$OGRNO); + $this->db->where('Status !=',OGR_PARTIAL_COMPLETE); + + $query = $this->db->get(); + + if ($query->num_rows == 0) { + $this->db->where('OGRNO', $OGRNO); + $OGRStatus = array('status'=>OGR_PARTIAL_COMPLETE); + $this->db->update('T_OGR_Master', $OGRStatus); + } + + else + { + $this->db->where('OGRNO', $OGRNO); + $OGRStatus = array('status'=>OGR_COMPLETE); + $this->db->update('T_OGR_Master', $OGRStatus); + } + } + + + + function UpdateMRIRMasterOGRStatus($MRIRNO,$OGRNO) + { + $this->db->select('*'); + $this->db->from('T_OGR_Details'); + $this->db->where('OGRNO',$OGRNO); + $this->db->where('Status !=',OGR_PARTIAL_COMPLETE); + + $query = $this->db->get(); + + if ($query->num_rows == 0) { + $this->db->where('MRIRNO', $MRIRNO); + $OGRStatus = array('OGRstatus'=>OGR_PARTIAL_COMPLETE); + $this->db->update('T_MRIR_Master', $OGRStatus); + } + + else + { + $this->db->where('MRIRNO', $MRIRNO); + $OGRStatus = array('OGRstatus'=>OGR_COMPLETE); + $this->db->update('T_MRIR_Master', $OGRStatus); + } + } + + + + function updateogrpomaster($pono) + { + $this->db->select('*'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO',$pono); + $this->db->where('OGR_Status !=','ST064'); + + $query = $this->db->get(); + + + if ($query->num_rows == 0) { + $this->db->where('PONO',$pono); + $POStatus = array('status'=>'ST063'); + $this->db->update('T_PurchaseOrder_Master', $POStatus); + } + } + + + + function getPOLineItemReceivedQty($PONO,$MaterialCode) + { + $this->db->select('ReceivedQuantity'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO',$PONO); + $this->db->where('MaterialCode',$MaterialCode); + $query = $this->db->get(); + // print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + + function GetMRIROutQty($MRIRNO,$MaterialCode) + { + $this->db->select('Ogr_Out_Qty'); + $this->db->from('T_MRIR_Details'); + $this->db->where('MRIRNO',$MRIRNO); + $this->db->where('MaterialCode',$MaterialCode); + $query = $this->db->get(); + // print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + + function getCustomer() + { + $subQuery='select client_id,client_name from ip_clients'; + $query = $this->db->query($subQuery); + //print_r( $this->db->last_query()); + return $query->result(); + + } + + + function getSupplier() + { + $subQuery='select SupplierID,SupplierName from T_SupplierDetailsN'; + $query = $this->db->query($subQuery); + //print_r( $this->db->last_query()); + return $query->result(); + + } + + + function getstoredmaterialcode() + { + $subQuery='select MaterialCode,MaterialName from T_MaterialMaster'; + $query = $this->db->query($subQuery); + return $query->result(); + } + + + + function getOGRData() + { + $this->db->select('T_OGR_Master.*,T_OGR_Details.*,T_SupplierDetailsN.SupplierName,sup.SupplierName as Servicesupplier'); + $this->db->from('T_OGR_Master'); + $this->db->join('T_OGR_Details','T_OGR_Details.OGRNO=T_OGR_Master.OGRNO'); + $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV','left'); + $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_PurchaseOrder_Master.SupplierID','left'); + $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=T_OGR_Details.SupplierID','left'); + $this->db->group_by('T_OGR_Master.OGRNO'); + //$this->db->where(); + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + + function getOGRDataforedit($OGRNO) + { + $this->db->select('T_OGR_Master.*,T_SupplierDetailsN.SupplierName,T_OGR_Details.*,sup.SupplierName as ServiceSupname,T_MaterialMaster.MaterialName as Matname,Remark'); + $this->db->from('T_OGR_Master'); + $this->db->join('T_OGR_Details','T_OGR_Details.OGRNO=T_OGR_Master.OGRNO'); + $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV','left'); + $this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_PurchaseOrder_Master.SupplierID','left'); + $this->db->join('T_SupplierDetailsN sup','sup.SupplierID=T_OGR_Details.SupplierID','left'); + + $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_OGR_Details.MaterialCode','left'); + $this->db->where('T_OGR_Master.OGRNO',$OGRNO); + //$this->db->group_by('T_OGR_Master.OGRNO'); + + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + + + function getOGRlineDataforedit($OGRNO,$MRIRNO) + { + $this->db->select('T_OGR_Details.*,MaterialName,ActualQuantityReceived,Quantity,QuantityRejected'); + $this->db->from('T_OGR_Details'); + $this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_OGR_Details.MaterialCode'); + $this->db->join('T_OGR_Master','T_OGR_Master.OGRNO=T_OGR_Details.OGRNO'); + $this->db->join('T_MRIR_Master','T_MRIR_Master.PONO=T_OGR_Master.PONO_INV','left'); + $this->db->join('T_MRIR_Details','T_MRIR_Details.MRIRNO=T_MRIR_Master.MRIRNO and T_MRIR_Details.MaterialCode=T_OGR_Details.MaterialCode'); + $this->db->join('T_PurchaseOrder_Master','T_PurchaseOrder_Master.PONO=T_MRIR_Master.PONO'); + $this->db->join('T_PurchaseOrder_LineItem','T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO and T_OGR_Details.MaterialCode=T_PurchaseOrder_LineItem.MaterialCode'); + $this->db->where('T_OGR_Details.OGRNO',$OGRNO); + $this->db->where('T_MRIR_Details.MRIRNO',$MRIRNO); + $this->db->group_by('T_OGR_Details.MaterialCode'); + + $query = $this->db->get(); + // print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + function getInvoice($CustomerId) + { + + $this->db->select('ip_invoices.invoice_id,invoice_number,item_product_id,item_name,item_quantity'); + $this->db->from('ip_invoices'); + $this->db->join('ip_invoice_items','ip_invoice_items.invoice_id = ip_invoices.invoice_id'); + $this->db->join('ip_clients','ip_invoices.client_id = ip_clients.client_id'); + + $this->db->where('ip_invoices.client_id',$CustomerId); + + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + + function getPOmrir($PONO) + { + $this->db->select('MRIRNO'); + $this->db->from('T_MRIR_Master'); + $this->db->where('T_MRIR_Master.PONO',$PONO); + $this->db->where('T_MRIR_Master.OGRstatus !=',OGR_COMPLETE); + // $this->db->where('Status !=',IGR_CREATED); + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + + } + + + + + function getPO($supplierId) + { + + /// echo $supplierId; + $subQuery='select T_PurchaseOrder_Master.PONO from T_PurchaseOrder_Master + join T_MRIR_Master on T_MRIR_Master.PONO= T_PurchaseOrder_Master.PONO + where T_PurchaseOrder_Master.SupplierID=? and (T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=? or T_PurchaseOrder_Master.Status=?) group by T_PurchaseOrder_Master.PONO'; + + //$query= $this->db->query($subQuery, array($supplierId,ST044,PO,ST063)); + $query= $this->db->query($subQuery, array($supplierId,ST044,PO,PO_RELEASED,IGR_CREATED,MRIR_CREATED,PARTIAL_MRIRAPPROVED,OGR_COMPLETE,OGR_PARTIAL_COMPLETE,OGR_CREATED)); + //print_r( $this->db->last_query()); + return $query->result(); + + + } + + function getPODetails($PONO) + { + + $subQuery ='select distinct T_PurchaseOrder_Master.PONO,T_PurchaseOrder_LineItem.MaterialCode, +T_PurchaseOrder_LineItem.Quantity as Oqty,T_MRIR_Details.ActualQuantityReceived, +T_MRIR_Details.QuantityRejected,MaterialName,balance_Qty +from T_PurchaseOrder_Master +join T_PurchaseOrder_LineItem on T_PurchaseOrder_LineItem.PONO = T_PurchaseOrder_Master.PONO +join T_MRIR_Master on T_MRIR_Master.PONO = T_PurchaseOrder_Master.PONO +join T_MRIR_Details on T_MRIR_Master.MRIRNO = T_MRIR_Details.MRIRNO and T_PurchaseOrder_LineItem.MaterialCode=T_MRIR_Details.MaterialCode +join T_MaterialMaster on T_MRIR_Details.MaterialCode=T_MaterialMaster.MaterialCode +left join T_OGR_Master on T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV +left join T_OGR_Details on T_OGR_Master.OGRNO=T_OGR_Details.OGRNO and T_PurchaseOrder_LineItem.MaterialCode= T_OGR_Details.MaterialCode +where T_PurchaseOrder_Master.PONO=?'; + + $query = $this->db->query($subQuery, array($PONO)); + //print_r($this->db->last_query()); + return $query->result(); + + + } + + + + function getPOMRIRDetails($MRIRno,$PONO,$materialcode) + { + $subQuery='select T_MRIR_Details.MaterialCode,ActualQuantityReceived,QuantityAccepted,QuantityRejected, +MaterialName,Quantity as Oqty,SUM(Ogr_Out_Qty) as allowedQty +from T_MRIR_Details +join T_MaterialMaster on T_MRIR_Details.MaterialCode=T_MaterialMaster.MaterialCode +join T_MRIR_Master on T_MRIR_Details.MRIRNO = T_MRIR_Master.MRIRNO +join T_PurchaseOrder_LineItem on T_MRIR_Master.PONO = T_PurchaseOrder_LineItem.PONO and T_PurchaseOrder_LineItem.MaterialCode=T_MRIR_Details.MaterialCode +where T_MRIR_Details.MRIRNO=? and T_MRIR_Master.PONO=? and T_MRIR_Details.MaterialCode=? group by T_MRIR_Details.MaterialCode;'; + $query = $this->db->query($subQuery, array($MRIRno,$PONO,$materialcode)); + //print_r($this->db->last_query()); + return $query->result(); + + + } + + + function getPOMRIRMaterial($MRIRno,$PONO) + { + $this->db->select('MaterialCode'); + $this->db->from('T_MRIR_Details'); + $this->db->join('T_MRIR_Master','T_MRIR_Master.MRIRNO=T_MRIR_Details.MRIRNO'); + $this->db->where('T_MRIR_Details.MRIRNO',$MRIRno); + $this->db->where('PONO',$PONO); + $this->db->group_by('T_MRIR_Details.MaterialCode'); + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + + } + + + function gettotalout($PONO,$materialcode) + { + $subQuery='select SUM(Ogr_Out_Qty) +from T_MRIR_Details +join T_MRIR_Master on T_MRIR_Master.MRIRNO= T_MRIR_Details.MRIRNO +where PONO =? and MaterialCode = ?; '; + +$query = $this->db->query($subQuery, array($PONO,$materialcode)); + //print_r($this->db->last_query()); + return $query->result(); + } + + + + + + + + function getPOmaterialDetails($PONO,$materialcode) + { + $subQuery='select distinct T_PurchaseOrder_LineItem.MaterialCode,MaterialName,T_PurchaseOrder_LineItem.Quantity as Oqty,T_MRIR_Details.ActualQuantityReceived,T_MRIR_Details.QuantityRejected,balance_Qty + from T_PurchaseOrder_Master +join T_PurchaseOrder_LineItem on T_PurchaseOrder_LineItem.PONO = T_PurchaseOrder_Master.PONO +join T_MRIR_Master on T_MRIR_Master.PONO = T_PurchaseOrder_Master.PONO +join T_MRIR_Details on T_MRIR_Master.MRIRNO = T_MRIR_Details.MRIRNO and T_PurchaseOrder_LineItem.MaterialCode=T_MRIR_Details.MaterialCode +join T_MaterialMaster on T_MRIR_Details.MaterialCode=T_MaterialMaster.MaterialCode +left join T_OGR_Master on T_PurchaseOrder_Master.PONO=T_OGR_Master.PONO_INV +left join T_OGR_Details on T_OGR_Master.OGRNO=T_OGR_Details.OGRNO and T_PurchaseOrder_LineItem.MaterialCode= T_OGR_Details.MaterialCode +where T_PurchaseOrder_LineItem.PONO=? and T_PurchaseOrder_LineItem.MaterialCode=?' +; +$query = $this->db->query($subQuery, array($PONO,$materialcode)); + // print_r($this->db->last_query()); + return $query->result(); + } + + +function getPOmaterial($PONO) +{ + $subQuery ='select MaterialCode from T_PurchaseOrder_LineItem where PONO=?'; + + $query = $this->db->query($subQuery, array($PONO)); + //print_r($this->db->last_query()); + return $query->result(); +} + + + + function AddOGR($ogrmaster) + { + $this->db->trans_start(); + $this->db->insert('T_OGR_Master', $ogrmaster); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + //print_r($insert_id); + if($insert_id>0) + { + //$subQuery = 'select max(OGRNO) as OGRNO from T_OGR_Master'; + $subQuery = 'select OGRNO from T_OGR_Master order by CreatedOn desc limit 1'; + + $query = $this->db->query($subQuery); + + return $query->result(); + } + } + + + + + function getlastogrline() + { + // $subQuery = 'select max(OGRItemNO) as OGRItemNO from T_OGR_Details'; + $subQuery = 'select OGRItemNO from T_OGR_Details order by CreatedOn desc limit 1'; + + $query = $this->db->query($subQuery); + + return $query->result(); + } + + + function UpdateOGR($updateogrmaster,$OGRNO) + { + $this->db->where('OGRNO',$OGRNO); + //$this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_OGR_Master', $updateogrmaster); + + return TRUE; + } + + + function AddOgrLine($Ogrline) + { + $this->db->trans_start(); + $this->db->insert('T_OGR_Details',$Ogrline); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; + } + + + // function GetIGR_Details($pono) + // { + // $this->db->select('IGRNO,MRIRNO,MaterialCode,'); + // $this->db->from('ip_invoices'); + // $this->db->join('ip_invoice_items','ip_invoice_items.invoice_id = ip_invoices.invoice_id'); + // $this->db->join('ip_clients','ip_invoices.client_id = ip_clients.client_id'); + + // $this->db->where('ip_invoices.client_id',$CustomerId); + + // $query = $this->db->get(); + // //print_r( $this->db->last_query()); + // $result = $query->result(); + // return $result; + // } + + + + + function GetPreSavedQty($pono,$MaterialCode) + { + // $subQuery = 'select Total_OutwardQty from T_PurchaseOrder_LineItem where PONO=? and MaterialCode=?'; + // $query = $this->db->query($subQuery, array($pono,$MaterialCode)); + // //print_r($this->db->last_query()); + // return $query->result(); + + + $this->db->select('Total_OutwardQty'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO',$pono); + $this->db->where('MaterialCode',$MaterialCode); + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + + } + + + function check_PO($pono) + { + $subQuery='select * from T_OGR_Master where PONO_INV=?'; + $query=$this->db->query($subQuery,array($pono)); + return $query->result(); + } + + + function UpdatePOMasterOGR($postatus,$pono) + { + $this->db->where('PONO',$pono); + //$this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_PurchaseOrder_Master', $postatus); + + return TRUE; + } + + function updateigr($igrarr,$IGRNo){ + + //$this->db->where('PONO',$PONO); + $this->db->where('IGRNO',$IGRNo); + $this->db->update('T_IGR_Master',$igrarr); + $r = $this->db->affected_rows(); + return $r; + } + function getpolineqty($NewPO) +{ + $this->db->select('sum(Quantity)as Qty,sum(ReceivedQuantity)as rec'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO',$NewPO); + + $query = $this->db->get(); + return $query->result(); +} + + +function POLineItemsupdatestatus($PONO,$Newstatus) +{ + $this->db->where('PONO',$PONO); + $this->db->update('T_PurchaseOrder_LineItem',$Newstatus); + $update = $this->db->affected_rows(); + return $update; + +} + +function pomasterupdatestatus($PONO,$Newstatus) +{ + $this->db->where('PONO',$PONO); + $this->db->update('T_PurchaseOrder_Master',$Newstatus); + $update = $this->db->affected_rows(); + return $update; +} + } \ No newline at end of file diff --git a/application/models/mrir_model.php b/application/models/mrir_model.php index 420e4016..feb4efc9 100644 --- a/application/models/mrir_model.php +++ b/application/models/mrir_model.php @@ -189,8 +189,7 @@ TMD.QuantityRejected,ST.StatusName,TMD.Remarks,AdvanceAmount '); if($insert_id>0) { - // $subQuery = 'select max(MRIRNO) as MRIRNo from T_MRIR_Master'; - $subQuery = 'select MRIRNO from T_MRIR_Master order by Createdon desc limit 1'; + $subQuery = 'select max(MRIRNO) as MRIRNo from T_MRIR_Master'; $query = $this->db->query($subQuery); return $query->result();//_array(); } diff --git a/application/models/purchaseorder_model.php b/application/models/purchaseorder_model.php index 5570808e..1b24bc9a 100644 --- a/application/models/purchaseorder_model.php +++ b/application/models/purchaseorder_model.php @@ -1,2545 +1,2545 @@ -db->distinct(); - $this->db->select('PO.PONO'); - $this->db->from('T_PurchaseOrder_Master PO'); - $this->db->join('T_PurchaseOrder_LineItem Line','PO.PONO = Line.PONO'); - $this->db->join('T_Requestion_Master Req','Req.ReqNo = Line.ReqNo'); - - $this->db->where('PO.POType',SERVICE); - $this->db->where('PO.status',PO_RELEASED); - $this->db->where('Req.RequestedDept',$this->session->userdata('DEPCode')); - - - - $query = $this->db->get(); - // print_r( $this->db->last_query()); - return $query->result(); - } - - - - -/*------------jun15------------------*/ - - -function getfies($pono) - { - - $this->db->select('*'); - - - $this->db->from('T_PurchaseOrder_BillUpload bill'); - - $this->db->where('PONO',$pono); - - $query = $this->db->get(); - - return $query->result(); - } -/*-----------jun15-------------------*/ - - - function updateMatStock($itemNo, - $MaterialstockHistoryupdate){ - //echo'hi'; - - - $this->db->where('Ref_No',$itemNo); - $this->db->update('T_Material_stock_history', $MaterialstockHistoryupdate); - - $r = $this->db->affected_rows(); - return $r; -} - - - - -function updateReqDetails($Reqnumber,$MaterialCode,$ReqDetail){ - //echo'hi'; - - $this->db->where('ReqNo',$Reqnumber); - $this->db->where('MaterialCode',$MaterialCode); - // $this->db->where('Quantity',$Quantity); - - $this->db->update('T_Requestion_Details',$ReqDetail); - - $r = $this->db->affected_rows(); - return $r; -} - - -function IGRDetailsupdate($PONO) -{ - //echo 'hi'; - - - $subQuery ='select IGRM.PONO,IGRD.IGRItemNo,IGRD.IGRNO from -T_IGR_Master IGRM -join T_IGR_Details IGRD on IGRD.IGRNO = IGRM.IGRNO -Where IGRM.PONO = ? '; - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result_array(); - - - } - - - function updateIGR($IGRItemNo,$IGRDs) //,$MaterialCode, - { - //print_r(array($IGRDs,$IGRItemNo)); - - $this->db->where('IGRItemNo',$IGRItemNo); //,'IGRNO',$IGRNO,'MaterialCode',$MaterialCode); - //$this->db->where('IGRNO',$IGRNO); - // $this->db->where('MaterialCode',$MaterialCode); - $this->db->update('T_IGR_Details',$IGRDs); - - $r = $this->db->affected_rows(); - - // $this->db->last_query(); - - return $r; - - - - - - - } - - - - - -/*------------------------------*/ - - - /////////////////// start this function used to pono reset financeyear configuration - - function ponoreset($ponoreset) - { - - //print_r($ponoreset); die; - $this->db->insert('T_PONO_Reset_Table',$ponoreset); - - $r = $this->db->affected_rows(); - return $r; - } - - - function updateponoreset($ponoreset,$sno,$potype,$posubtype) -{ - - - $this->db->where('reset_pono_id',$sno,'POType',$potype,'POSubtype',$posubtype); - $this->db->update('T_PONO_Reset_Table',$ponoreset); - $r = $this->db->affected_rows(); - return $r; - -} - - function ponoresetfinyear() - { - $this->db->select('*'); - $this->db->from('T_PONO_Reset_Table'); - $query =$this->db->get(); - return $query->result(); - } - ///////////////////end this function used to pono reset financeyear configuration - - - - - function fileupload($myfile) - { - - //print_r($myfile);die; - - $this->db->insert('T_PurchaseOrder_BillUpload',$myfile); - $myfile=$this->db->affected_rows(); - return $myfile; - } - - /*--------------------------------------------------*/ -/* this function used parendpo igr values get inward report display */ -function updateigrmaster($igrno,$NewPOno) -{ - // $this->db->insert('T_IGR_Master',$IGRaddvalues); - // $myfile=$this->db->affected_rows(); - // return $myfile; - - $this->db->where('IGRNO',$igrno); - $this->db->update('T_IGR_Master',$NewPOno); - $insert_id = $this->db->affected_rows(); - return $insert_id; -} -function updateigrfile($igrno,$NewPOno) -{ - $this->db->where('IGRNO',$igrno); - $this->db->update('T_Inwardgateregister_fileupload',$NewPOno); - $insert_id = $this->db->affected_rows(); - return $insert_id; - -} - -function selectigrmaster($PONO) -{ - -$this->db->select('*'); -$this->db->from('T_IGR_Master'); -$this->db->where('PONO',$PONO); - $query = $this->db->get(); - return $query->result(); - -} - - - -function getpolineqty($NewPO) -{ - $this->db->select('sum(Quantity)as Qty,sum(ReceivedQuantity)as rec'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO',$NewPO); - - $query = $this->db->get(); - return $query->result(); -} - - -function POLineItemsupdatestatus($NewPO,$Newstatus) -{ - $this->db->where('PONO',$NewPO); - $this->db->update('T_PurchaseOrder_LineItem',$Newstatus); - $update = $this->db->affected_rows(); - return $update; - -} - -function pomasterupdatestatus($NewPO,$Newstatus) -{ - $this->db->where('PONO',$NewPO); - $this->db->update('T_PurchaseOrder_Master',$Newstatus); - $update = $this->db->affected_rows(); - return $update; -} - - -/*--------------------------------------------------*/ - - - - - function getfunction($pono) - { - $this->db->distinct(); - $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType'); - $this->db->from('T_PurchaseOrder_BillUpload bill'); - $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left'); - $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); - // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); - $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO'); - $this->db->where('bill.PONO',$pono); - //$this->db->or_where('pom.status',SPECIAL_PO); - $this->db->group_by('bill.BillNo'); - - - - - -// $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo, -// mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate, -// mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType'); - -// $this->db->from('T_IGR_Master mstr'); -// $this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left'); -// $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); -// // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); -// $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO'); -// $this->db->where('mstr.PONO',$pono); - - $query = $this->db->get(); - - return $query->result(); - } - -function getfunctionr($pono) - { - $this->db->distinct(); - // $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType'); - // $this->db->from('T_PurchaseOrder_BillUpload bill'); - // $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left'); - // $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); - // // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); - // $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO'); - // $this->db->where('bill.PONO',$pono); - // //$this->db->or_where('pom.status',SPECIAL_PO); - // $this->db->group_by('bill.BillNo'); - - - - - - $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo, -mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate, -mstr.CourierNo,pom.Status,pom.POType'); //,bill.BillNo,bill.FilePath, - - $this->db->from('T_IGR_Master mstr'); - //$this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left'); - $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); - // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); - $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO'); - $this->db->where('mstr.PONO',$pono); - - $query = $this->db->get(); - - return $query->result(); - } - - -function getbillfiesr($pono) - { - $this->db->distinct(); - // $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType'); - // $this->db->from('T_PurchaseOrder_BillUpload bill'); - // $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left'); - // $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); - // // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); - // $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO'); - // $this->db->where('bill.PONO',$pono); - // //$this->db->or_where('pom.status',SPECIAL_PO); - // $this->db->group_by('bill.BillNo'); - - - - - - $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo, -mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate, -mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType'); - - $this->db->from('T_IGR_Master mstr'); - $this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left'); - $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); - // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); - $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO'); - $this->db->where('mstr.PONO',$pono); - - $query = $this->db->get(); - - return $query->result(); - } - - - - function GetPODetailforBillingServicePO($PONO) - { - - $subQuery ='select mast.ReqNo,mast.ReqDate,supp.SupplierName,PODate,st.StatusName as WorkStatus,ServiceWorkStatus,POMast.PaymentTerms, - POMast.ServiceWorkStatus,LineItem.*,mat.MaterialName,mat.UOM,emp.FirstName,emp.LastName,POMast.TotalOrderValue - from T_PurchaseOrder_Master POMast - join T_PurchaseOrder_LineItem LineItem on LineItem.PONO = POMast.PONO - join T_SupplierDetailsN supp on supp.SupplierID = POMast.SupplierID - join T_MaterialMaster mat on mat.MaterialCode = LineItem.MaterialCode - join T_Status Stat on Stat.StatusCode = POMast.Status - join T_Status st on st.StatusCode = POMast.ServiceWorkStatus - join T_Requestion_Master mast on mast.ReqNo = LineItem.ReqNo - join tbl_users users on users.userId = mast.CreatedBy - join T_Employee_Details emp on emp.EmpID = users.EmpID - where POMast.POType=? and POMast.PONO=?'; - - $query = $this->db->query($subQuery,array(SERVICE,$PONO)); - - return $query->result_array(); - - } - - function GetServicePOListforBilling() - { - $subQuery ='select POMast.PONO,supp.SupplierName,PODate,POMast.PaymentTerms,POMast.ServiceWorkStatusRemarks,StatusName,POMast.CapitalRange,POType, - LineItem.*,mat.MaterialName,mat.UOM,emp.FirstName,emp.LastName,Tax.TotalValue,Cost.CostCenterName,AdvanceAmount - ,Dept.DepartmentName from T_PurchaseOrder_Master POMast - join T_PurchaseOrder_LineItem LineItem on LineItem.PONO = POMast.PONO - join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - left join T_PurchaseOrder_AdvanceRequest PUADV on POMast.PONO=PUADV.PONO - join T_SupplierDetailsN supp on supp.SupplierID = POMast.SupplierID - join T_MaterialMaster mat on mat.MaterialCode = LineItem.MaterialCode - join T_Status Stat on Stat.StatusCode = POMast.Status - join T_Requestion_Master mast on mast.ReqNo = LineItem.ReqNo - join tbl_users users on users.userId = POMast.CreatedBy - left join T_Employee_Details emp on emp.EmpID = mast.Requestedby - join T_DepartmentDetails Dept on Dept.DEPCode = mast.RequestedDept - join T_CostCenter_Master Cost on Cost.CostCenterCode=LineItem.CostCenterCode - where POMast.POType=? and ServiceWorkStatus=? order by POMast.UpdatedOn desc'; - - $query = $this->db->query($subQuery,array(SERVICE,SERVICE_COMPLETED)); - - //print_r( $this->db->last_query()); - return $query->result(); - - } - - /** - * This function is used to get the user listing count - * @param string $searchText : This is optional search text - * @return number $count : This is row count - */ - function purchaseorderListingCount() - { - $this->db->distinct(); - $this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Req.ReqType,DeliveryDate'); - $this->db->from('T_PurchaseOrder_Master POMast'); - $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID'); - $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status'); - $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO'); - $this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo'); - // print_r( $this->db->last_query()); - $query = $this->db->get(); - - return count($query->result()); - } - - /** - * This function is used to get the user listing count - * @param string $searchText : This is optional search text - * @param number $page : This is pagination offset - * @param number $segment : This is pagination limit - * @return array $result : This is result - */ - -function purchaseorderListing($forwhat='') - { - $this->db->distinct(); - $this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Stat.StatusCode,POMast.POType as ReqType,DeliveryDate,DeliverySchedule,DeliveryOption,POMast.CapitalRange,POMast.UpdatedOn'); - $this->db->from('T_PurchaseOrder_Master POMast'); - $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID'); - $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status'); - $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO'); - $this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo'); - if($forwhat=='amendment') - { - $this->db->where('POMast.Status',PO_RELEASED); - } - else - { - $this->db->where('POMast.Status !=',PO_AMENDED); - // $this->db->order_by('POMast.Status !=',PO_AMENDED); - } - $this->db->order_by('POMast.UpdatedOn','desc'); - $query = $this->db->get(); - //print_r( $this->db->last_query()); - $result = $query->result(); - return $result; - } - - /** - * This function is used to get the SupplierID and SupplierName information - * @return array $result : This is result of the query - */ - function getSupplierName($supID='') - { - $this->db->select('SupplierID, SupplierName,Address,PaymentID'); - $this->db->from('T_SupplierDetailsN'); - $this->db->where('IsActive', 1); - if($supID != '') - { - $this->db->where('SupplierID',$supID); - } - //$this->db->where('roleId !=', 1); - $query = $this->db->get(); - - return $query->result(); - } - /** - * This function is used to get the userId information - * @return array $result : This is result of the query - */ - function getusers() - { - $this->db->select('userId, name'); - $this->db->from('tbl_users'); - //$this->db->where('roleId !=', 1); - $query = $this->db->get(); - - return $query->result(); - } - - - function getqtycheck($PONO) - { - $this->db->select('IsQualityChkReqired'); - $this->db->from('T_PurchaseOrder_Master'); - $this->db->where('PONO',$PONO); - $query = $this->db->get(); - - return $query->result(); - - } -/** - * This function is used to get the Raw Material information - * @return array $result : This is result of the query - */ - function getRawPOMaterialList($ReqNo,$IsArray='') - { - - $result = $this->db-> query("CALL P_GET_REQUISTIONLIST('".$ReqNo."')") or die(mysql_error()); - - $result ->next_result(); - - //print_r($this->db->last_query()); - - if ($result->num_rows > 0) - { - //echo 'PO Line item Inserted successfully'; - if($IsArray != '') - { - return $result->result_array(); - } - else - { - return $result->result(); - } - } - - } - - /** - This Function to get the List of Requistion which require to create PO - */ - function getAllRequistionListToCreatePO() - { - $result = $this->db-> query("CALL P_PURCHASEORDER_DETAILS()") or die(mysql_error()); - - $result ->next_result(); - - - if ($result->num_rows > 0) - { - - return $result->result(); - } - } - - /** - * This function is used to get the Raw Material information - * @return array $result : This is result of the query - */ - function getRawMaterialList($MatType='',$ReqNoList='') - { - - $this->db->select('ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity'); - $this->db->from('T_Requestion_Details Req'); - $this->db->join('T_MaterialMaster mat', 'Req.MaterialCode = mat.MaterialCode'); - $this->db->where('mat.MaterialType', $MatType); - $this->db->where_in('Req.ReqNo', $ReqNoList); - - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); - } - /** - * This function is used to get the Raw Material information - * @return array $result : This is result of the query - */ - function getRawMaterialListForPO($MatType='',$ReqNo='') - { - $subQuery ='SELECT ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity - FROM T_Requestion_Details Req - JOIN T_MaterialMaster mat ON Req.MaterialCode = mat.MaterialCode - where mat.MaterialType = ? - AND Req.ReqNo = ? - AND mat.MaterialCode != (SELECT MaterialCode FROM T_PurchaseOrder_LineItem WHERE ReqNo =? - )'; - - $query = $this->db->query($subQuery,array($MatType,$ReqNo,$ReqNo)); - - return $query->result_array(); - - - } - //Import PO Available Budget Amount - function GetAvailableImportBudgetAmount($CostCode,$Year,$BudgetType) - { - $subQuery='select BudgetAmount,(select ifnull(sum((Quantity*Rate*ExchangeRate)),0)as TValue from T_PurchaseOrder_LineItem LineItem - join T_PurchaseOrder_Master Mast on Mast.PONO=LineItem.PONO where POType=? - and CostCenterCode=? and Mast.status not in (?) )as Totalvalue from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and BudgetYear=? and BudgetType=?'; - $query = $this->db->query($subQuery,array($BudgetType,$CostCode,PO_AMENDED,$CostCode,$Year,$BudgetType)); - //print_r($this->db->last_query()); - return $query->result_array(); - - - } - //get available budget for capital - function GetAvailableCapitalBudgetAmount($CostCode,$Year,$BudgetType) - { - - $subQuery ='select BudgetAmount, (select ifnull(sum(IF(POMaster.ExchangeRate>0,Quantity*Rate*POMaster.ExchangeRate,Quantity*Rate-tax.Afterdiscountval)),0) as Totalvalue from - T_PurchaseOrder_LineItem Item join T_Requestion_Master mast - on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POMaster on POMaster.PONO=Item.PONO left join T_Service_Tax tax on tax.LineItemNo=Item.LineItemNo where Item.CostCenterCode=? and POMaster.POType=? and POMaster.status not in (?))as Totalvalue - from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and - BudgetYear = ? and BudgetType =?'; - - $query = $this->db->query($subQuery,array($CostCode,$BudgetType,PO_AMENDED,$CostCode,$Year,$BudgetType)); - - return $query->result_array(); - - } - function GetAvailableBudgetAmount($CostCode,$Year,$BudgetType) - { - $subQuery ='select distinct Bud.CostCenterCode,BudgetAmount, case WHEN BudgetType = ? then (select - round(ifnull(sum((Quantity*Rate)-ifnull(tax.AfterDiscount,0)),0),2) as - Totalvalue from T_PurchaseOrder_LineItem Item join T_Requestion_Master mast - on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POM on POM.PONO = Item.PONO left join T_Revenue_Tax tax on - tax.LineItemNo = Item.LineItemNo - where Item.CostCenterCode=? and POM.POType=? and POM.status not in (?)) else (select - round(ifnull(sum(Quantity*Rate*ifnull(case when mast.NumberOfService=? - then 1 else mast.NumberOfService end ,1)),0),2) as - Totalvalue from T_PurchaseOrder_LineItem Item join T_Requestion_Master mast - on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POM on POM.PONO = Item.PONO left join T_Requestion_Master ReqMas on ReqMas.ReqNo= Item.ReqNo - where Item.CostCenterCode=? and POM.POType=? and POM.status not in (?) ) end as Totalvalue - from T_CostCenter_Budget Bud join T_CostCenter_Departments dept on dept.CostCenterCode = Bud.CostCenterCode - where Bud.CostCenterCode=? and - BudgetYear = ? and BudgetType =?'; - - - $query = $this->db->query($subQuery,array(REVENUE,$CostCode,$BudgetType,PO_AMENDED,'0.00',$CostCode,$BudgetType,PO_AMENDED,$CostCode,$Year,$BudgetType)); - - - //print_r($this->db->last_query()); - return $query->result_array(); - - } - - //to get POTYpe from ReqNo -function GetPOType($ReqNo) -{ - $this->db->select('POType'); - $this->db->from('T_PurchaseOrder_Master mast'); - $this->db->join('T_PurchaseOrder_LineItem Line', 'mast.PONO=Line.PONO'); - $this->db->where('Line.ReqNo', $ReqNo); - $query = $this->db->get(); - return $query->result_array(); -} - - /** - * This function is used to get the Requsition List for the login user - * @return array $result : This is result of the query - */ - function getRequistDetails($ReqNoList='') - { - $ReqDeatis = $this->GetRequistionMasterUsingReqNo($ReqNoList); - - foreach ($ReqDeatis as $SID): - $ReqBy = $SID->Requestedby ; - - endforeach; - if($ReqBy=='' || $ReqBy==null){ - $this->db->distinct(); - $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,mast.Schedule_Type,mast.NumberOfService,mast.Service_Period, - Dept.DEPCode,Dept.DepartmentName,mast.ReqDate,mast.CostCenterCode,mast.Status'); - $this->db->from('T_Requestion_Master mast'); - - $this->db->join('T_DepartmentDetails Dept', 'mast.RequestedDept = Dept.DEPCode'); - $this->db->where_in('mast.ReqNo', $ReqNoList); - } - - else if($ReqBy!='') { - $this->db->distinct(); - $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,mast.Schedule_Type,mast.NumberOfService,mast.Service_Period,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate,mast.CostCenterCode,mast.Status'); - $this->db->from('T_Requestion_Master mast'); - $this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID'); - $this->db->join('T_DepartmentDetails Dept', 'mast.RequestedDept = Dept.DEPCode'); - $this->db->where_in('mast.ReqNo', $ReqNoList); - } - - - $query = $this->db->get(); - - return $query->result(); - } - /** - * This function is used to get the Requsition List for the login user - * @return array $result : This is result of the query - */ - function getRequistDetailsForPO($ReqNoList='') - { - $this->db->distinct(); - $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate'); - $this->db->from('T_Requestion_Master mast'); - $this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID'); - $this->db->join('T_DepartmentDetails Dept', 'emp.Departmentcode = Dept.DEPCode'); - $this->db->where_in('mast.ReqNo', $ReqNoList); - - $query = $this->db->get(); - - return $query->result(); - } - /** - * This function is used to get the Cost center information - * @return array $result : This is result of the query - */ - function getCostCenter() - { - - $this->db->select('CostName, Description'); - $this->db->from('T_CostCentre'); - - $query = $this->db->get(); - - return $query->result(); - } - - - /** - * This function is used to get the CostCenter for the Selected Requistion Number - * @return array $result : This is result of the query - */ - function getCostCenterbyRequist($ReqNo='',$BudYear='',$ReqType='') - { - - $this->db->distinct(); - $this->db->select('Mast.CostCenterCode,Mast.CostCenterName,Bud.BudgetAmount,ReqNo'); - $this->db->from('T_CostCenter_Master Mast'); - $this->db->join('T_CostCenter_Departments CostDept', 'CostDept.CostCenterCode = Mast.CostCenterCode'); - $this->db->join('T_CostCenter_Budget Bud', 'Bud.CostCenterCode = Mast.CostCenterCode'); - $this->db->join('T_Employee_Details emp', 'CostDept.DEPCode = emp.Departmentcode'); - $this->db->join('T_Requestion_Master req', 'req.Requestedby = emp.EmpID'); - - $this->db->where('BudgetType ',$ReqType ); - $this->db->where('BudgetYear ',$BudYear ); - if($ReqNo != '') - { - $this->db->where('ReqNo ',$ReqNo); - } - - $query = $this->db->get(); - return $query->result(); - } - -/** - * This function is used to get the Config value from configuration table - * @return array $result : This is result of the query - */ - function getRequistionNoFromPO($PONO='') - { - $this->db->distinct(); - $this->db->select('ReqNo,'); - $this->db->from('T_PurchaseOrder_LineItem'); - if($PONO != '') - { - $this->db->where('PONO ',$PONO ); - } - - $query = $this->db->get(); - - return $query->result(); - } - - - /** - * This function is used to get the Config value from configuration table - * @return array $result : This is result of the query - */ - function getConfigValue($ConfigID ,$ConfigValue = '') - { - - $this->db->select('ConfigValue'); - $this->db->from('T_ConfigDetails'); - $this->db->where('Config_id ',$ConfigID ); - if($ConfigValue != '') - { - $this->db->where('ConfigValue != ',$ConfigValue ); - } - $query = $this->db->get(); - - return $query->result(); - } - - - - - /** - * This function is used to get the Company information from T_Company_Details table - * @return array $result : This is result of the query - */ - function getCompanyInformation() - { - - $subQuery = "select CompanyName,replace(Address,'
    ','') as Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode - from T_Company_Details "; - - - - $query = $this->db->query($subQuery); - - - //print_r($this->db->last_query()); - return $query->result(); - // return $query->result(); - } - /** - * This function is used to get the Company information from T_Company_Details table - * @return array $result : This is result of the query - */ - function getCompanyInformationforPDF() - { - - $subQuery = "select CompanyName,Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode - from T_Company_Details "; - - - - $query = $this->db->query($subQuery); - - - //print_r($this->db->last_query()); - return $query->result(); - // return $query->result(); - } - - /** - * This function is used to get the Employee List - * @return array $result : This is result of the query - */ - function getAllEmployees() - { - $this->db->select('EmpID,FirstName,LastName'); - $this->db->from('T_Employee_Details'); - $query = $this->db->get(); - - return $query->result(); - } - - /** - * This function is used to get the Employee List - * @return array $result : This is result of the query - */ - function getLastCreatedPODate() - { - $this->db->select('max(PODate) as PODate'); - $this->db->from('T_PurchaseOrder_Master'); - $query = $this->db->get(); - - return $query->result(); - } - - function getLastReleasedPODate() - { - $this->db->select('max(ReleasedOn) as PODate'); - $this->db->from('T_PurchaseOrder_Master'); - $query = $this->db->get(); - - return $query->result(); - } - /** - * This function is used to add New Purchase order to the system - - */ - function addPOMaster($POMaster,$POType,$POSubtype) - { - $this->db->trans_start(); - $this->db->insert('T_PurchaseOrder_Master', $POMaster); - //$this->db->update('T_PONO_Reset_Table') - - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - if($insert_id>0) - { - $subQuery = 'select PONO from T_PurchaseOrder_Master where POType=? and POSubType=? and isnull(ParentPO) order by CreatedDate desc limit 1 '; - - $query = $this->db->query($subQuery,array($POType,$POSubtype)); - - //print_r($query->result());die(); - return $query->result_array(); - } - } - - - - - - function addAmendPOMaster($POMaster,$CreatedBy,$ParentPO) - { - // print_r($POMaster); - $this->db->trans_start(); - $this->db->insert('T_PurchaseOrder_Master', $POMaster); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - if($insert_id>0) - { - $subQuery = 'select PONO from T_PurchaseOrder_Master where CreatedBy=? and ParentPO=? order by CreatedDate desc limit 1'; - - $query = $this->db->query($subQuery,array($CreatedBy,$ParentPO)); - - return $query->result_array(); - } - } - - /** - * This function is used to add New Purchase order Line Item to the system - */ - function addPOLineItem($POLineItem) - { - $this->db->trans_start(); - $this->db->insert('T_PurchaseOrder_LineItem', $POLineItem); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - if($insert_id>0) - { - // $subQuery = 'select max(LineItemNo) as LineItemNo from T_PurchaseOrder_LineItem'; - $subQuery = 'SELECT * FROM T_PurchaseOrder_LineItem where PONO = "'.$POLineItem['PONO'].'" ORDER BY LineItemNo DESC'; - - $query = $this->db->query($subQuery); - - return $query->result_array(); - } - } - - /** - * This function is used to add Revenue Tax to the system - */ - function addRevenueTax($RevenueTaxList) - { - $this->db->trans_start(); - $this->db->insert('T_Revenue_Tax', $RevenueTaxList); - $this->db->trans_complete(); - $insert_id = $this->db->insert_id(); - $aff_row = $this->db->affected_rows(); - // print_r( $this->db->last_query()); die(); - // echo "aff_row".$aff_row." $insert_id".$insert_id; - return $aff_row > 0 ? $this->db->insert_id() : 0; - } - /** - * This function is used to add Service Tax to the system - */ - function addServiceTax($ServiceTaxList) - { - $this->db->trans_start(); - $this->db->insert('T_Service_Tax', $ServiceTaxList); - $this->db->trans_complete(); - $insert_id = $this->db->affected_rows(); - return $insert_id>0 ? $this->db->insert_id() : 0; - } - - - /** - * This function is used to add Service Tax to the system - */ - function addImportTax($ImportTaxList) - { - $this->db->trans_start(); - $this->db->insert('T_Import_Tax', $ImportTaxList); - $this->db->trans_complete(); - $insert_id = $this->db->affected_rows(); - return $insert_id>0 ? $this->db->insert_id() : 0; - } - - - - function addadvanceRequest($advance) - { - $this->db->trans_start(); - $this->db->insert('T_PurchaseOrder_AdvanceRequest', $advance); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; - - - } - - function PONOExists($PONO) - { - - $this->db->select('PONO'); - $this->db->from('T_PurchaseOrder_AdvanceRequest'); - $this->db->where('PONO ',$PONO); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - return $query->result_array(); - } - - - } - - - - function updateadvanceRequest($advance,$PONO) - { - $this->db->where('PONO', $PONO); - $this->db->update('T_PurchaseOrder_AdvanceRequest',$advance); - $insert_id = $this->db->affected_rows(); - return $insert_id; - } - - - /** - * This function used to get user information by id - * @param number $userId : This is user id - * @return array $result : This is user information - */ - function getuserInfo($PO) - { - $this->db->select('POType, PODate, SupplierID,SpecialOrder,UserID,RequestedDate,RequesterEmail,RequesterPh, PurchasingCategory,BudgetManager,BudgetManagerDepartment,'); - $this->db->from('T_PurchaseOrderDetails'); - $this->db->where('PONO', $PO); - $query = $this->db->get(); - - return $query->result(); - } - - // This Method to get the Service PO Details for Edit the Item - - function GetServicePurchaseOrder($PONO = '') - { - $this->db->distinct(); - $this->db->select('ReqNo,POMast.PONO,POMast.PaymentTerms,POMast.PaymentOtherDescription,ServiceDescription,supp.SupplierID,supp.SupplierName,supp.Address,PODate,Stat.StatusName,DeliveryOption,DeliverySchedule,DeliveryDate,DeliveryAddress,POMast.PaymentTerms,POMast.ExchangeRate,POMast.UpdatedOn,Stat.StatusCode,POMast.ServiceWorkStatus,POMast.*,POMast.TotalOrderValue,POMast.BudgetType,IGR.IGRNO'); - $this->db->from('T_PurchaseOrder_Master POMast'); - $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID'); - $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status'); - $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO'); - $this->db->join('T_IGR_Master IGR','POMast.PONO = IGR.PONO','left'); - - $this->db->where('POMast.PONO', $PONO); - $query = $this->db->get(); - - $result = $query->result(); - - return $result; - } - - // This Method to get the Service PO Child Details for Edit the Item - - -// This Method to get the Service PO Child Details for Edit the Item - function GetServicePurchaseOrderDetails($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.Per,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,LineItem.Quantity,ReceivedQuantity,Rate,LineItem.Status,(LineItem.Quantity *Rate) as BasicValue ,(After_CGST + After_SGST + After_IGST) as Taxamount,Dept.DepartmentName - ,TotalValue,CGST,After_CGST,SGST,After_SGST,IGST,After_IGST,otherallowance,LineItem.CostCenterCode,LineItem.ServiceFrequency,LineItem.ServiceMaterialDescription,Req.Schedule_Type,Req.NumberOfService,Req.Service_Period,ReqDet.MaterialDescription - FROM T_PurchaseOrder_LineItem LineItem - join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo - join T_Requestion_Details ReqDet on ReqDet.ReqNo = LineItem.ReqNo and LineItem.MaterialCode = ReqDet.MaterialCode - left join T_Employee_Details emp on Req.Requestedby = emp.EmpID - join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode - where LineItem.PONO =?'; - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - // This Method to get the Service PO Child Details for Edit the Item - function GetServicePurchaseOrderDetailsforPdf($PONO = '') - { - - - - $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.Per,LineItem.ServiceMaterialDescription,Mat.MaterialCode,Mat.MaterialName,POMaster.ParentPO, - Mat.UOM,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue,POMaster.AmendedDetails,LineItem.AmendedDetails as lineamenddetails, - ROUND(( Tax.After_SGST + Tax.After_CGST + Tax.After_IGST ) ,2)as Taxamount,ReqMat.NumberOfService,ReqMat.Schedule_Type,ReqMat.Service_Period, - TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,Payment.PaymentTerms,AdvanceAmount - FROM T_PurchaseOrder_LineItem LineItem - join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO - join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID - join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms - join T_Requestion_Master ReqMat on ReqMat.ReqNo = LineItem.ReqNo - left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO - where LineItem.PONO =?'; - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - - - - // This Method to get the Revenue PO Child Details for Edit the Item - function GetRevenuePurchaseOrderDetails($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity,Per,ServiceMaterialDescription,ReceivedQuantity,Rate,Req.Status,(Quantity *Rate) as BasicValue , (( AfterSGST + AfterCGST + - AfterIGST )) as Taxamount ,TotalValue,Tax.*,Req.CostCenterCode,Dept.DepartmentName - FROM T_PurchaseOrder_LineItem LineItem - join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - left join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo - left join T_Employee_Details emp on Req.Requestedby = emp.EmpID - join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode - where LineItem.PONO =?'; - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - - // This Method to get the Revenue PO Child Details for Edit the Item - function GetRevenuePurchaseOrderDetailsForPDF($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,ReqNo,Mat.MaterialCode,Mat.MaterialName,POMaster.PaymentOtherDescription,LineItem.ServiceMaterialDescription, - Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue , - ROUND(((AfterSGST + AfterCGST + - AfterIGST)) ,2)as Taxamount,AdvanceAmount, - TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.Address,sup.SupplierID,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,LineItem.AmendedDetails as LineAmend,Payment.PaymentTerms - FROM T_PurchaseOrder_LineItem LineItem - left join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - left join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO - join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID - left join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms - left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO - where LineItem.PONO =?'; - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - - function getRevenueTaxinforforpdf($PONO) - { - $subQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,rt.CGST,rt.SGST,rt.IGST,rt.FreightValue,rt.AfterFreightValue,rt.PackagingValue,rt.AfterPackagingValue,rt.DiscountValue,rt.AfterDiscount FROM T_Revenue_Tax rt - - join T_PurchaseOrder_LineItem pl on pl.LineItemNo=rt.LineItemNo - - join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO - - where pm.POType=? and pm.PONO=? - - group by rt.CGST,rt.SGST,rt.IGST,rt.FreightValue,rt.PackagingValue,rt.AfterDiscount,rt.AfterFreightValue,rt.AfterPackagingValue ORDER BY rt.LineItemNo ASC'; - - $query = $this->db->query($subQuery,array("REVENUE",$PONO)); - - return $query->result(); - - } -// This Method to get the Revenue PO Child Details for Edit the Item - - -function GetImportPurchaseOrderDetailsForPDF($PONO = '') - { - - // $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName, - // Mat.UOM,Quantity,ReqMas.Requestedby,Rate,ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount, - // ProductPrice,Tax.*,LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.Address - // FROM T_PurchaseOrder_LineItem LineItem - // join T_Requestion_Master ReqMas on ReqMas.ReqNo=LineItem.ReqNo - // join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - // join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - // join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO - // join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID - // where LineItem.PONO =?'; - - $subQuery='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName,Import_DispatchDetails,LineItem.Per,LineItem.ServiceMaterialDescription, -Mat.UOM,Quantity,ReqMas.Requestedby,Rate,ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount , -ProductPrice,Tax.*,LineItem.CostCenterCode ,Date(ReqMast.ReqDate) as ReqDate,POMaster.*,sup.SupplierName,sup.Address,LineItem.AmendedDetails as LineAmend,AdvanceAmount, Pay.PaymentTerms as Pay,ROUND((Quantity *Rate),2 ) as BasicValue,HSNCODE,sup.EmailAddress,sup.SupplierID,sup.PAN,sup.ContactNumber,sup.GSTNO -FROM T_PurchaseOrder_LineItem LineItem -join T_Requestion_Master ReqMas on ReqMas.ReqNo=LineItem.ReqNo -join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode -join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo -join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO -join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID -left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO -join T_Requestion_Master ReqMast on LineItem.ReqNo=ReqMast.ReqNo -join T_PaymentTerms Pay on POMaster.PaymentTerms=Pay.PaymentID -where LineItem.PONO =?'; - - $query = $this->db->query($subQuery,array($PONO)); - //print_r($this->db->last_query()); - - return $query->result(); - - - } - - - function GetCurrencyDetail($Currency='') - { - - $subQuery='SELECT * from T_Currency_Details where Currency_Code=?'; - $query=$this->db->query($subQuery,array($Currency)); - //print_r($query); - return $query->result(); - - } - - - function GerRequesterName($Requester='') - { - $subQuery='SELECT EmpID,FirstName,Departmentcode from T_Employee_Details where EmpID=?'; - - $query=$this->db->query($subQuery,array($Requester)); - - return $query->result(); - } - - - function GerRequesterDep($Depcode='') - { - $subQuery='SELECT DepartmentName from T_DepartmentDetails where DEPCode=?'; - $query=$this->db->query($subQuery,array($Depcode)); - - return $query->result(); - - } - - function GerCurrencyCodeName($Currencycode='') - { - $subQuery='SELECT * from T_Currency_Details where Currency_Code=?'; - $query=$this->db->query($subQuery,array($Currencycode)); - //print_r($this->db->last_query()); - return $query->result(); - - } - - - function GetPOStatus($Status='') - { - $subQuery='SELECT StatusName from T_Status where StatusCode=?'; - $query=$this->db->query($subQuery,array($Status)); - return $query->result(); - - } - - - function GetPaymentTerms($PONO='') - { - $subQuery='SELECT PaymentTerms from T_PurchaseOrder_Master where PONO=?'; - $query=$this->db->query($subQuery,array($PONO)); - //print_r($query); - return $query->result(); - - } - - - - - // function getSupplierPayment($Currency='') - // { - - // $subQuery='select distinct PaymentTerms from T_SupplierDetailsN'; - // $query=$this->db->query($subQuery,array($Currency)); - // //print_r($this->db->last_query()); - // return $query->result(); - - // } - - function getSupplierPayment($Config_ID='') - { - - // $subQuery='select distinct PaymentTerms from T_SupplierDetailsN'; - $subQuery='select ConfigValue from T_ConfigDetails where Config_ID=?'; - $query=$this->db->query($subQuery,array($Config_ID)); - //print_r($this->db->last_query()); - return $query->result(); - - } - - function GetWorkStatus($Config_ID='') - { - $subQuery = 'select ConfigValue from T_ConfigDetails where Config_ID=?'; - $query=$this->db->query($subQuery,array($Config_ID)); - //print_r($query); - return $query->result(); - } - - - - - -function GetImportPurchaseOrderDetails($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName, -Mat.UOM,Quantity,Rate,Req.Status,ROUND((Quantity *Rate),2 ) as BasicValue,ReceivedQuantity, -QuantityRejected,ROUND(Quantity-ReceivedQuantity)as PendingQty,Per, - ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,LandingCharge,HighSeasSalesCharge,CustomDuty,ExciseDuty,ExciseDutyEdCess,CustomEdCess,POMast.ExchangeRate,AfterLandingCharge,AfterHighSeasSalesCharge,AfterCustomDuty,AfterExciseDuty,AfterExciseDutyEdCess,AddlExciseDuty,AfterAddlExciseDuty,Grossdutypayable,AvailableModvat,Grossexpensesduetocustomduty,purchaseratePerKG,CustomDutyExpensesPerKG,RMCIncludingCustomersPerKG,QuantityKG,BasicPriceInMTon,ProductPrice,CustomSHCess,AfterCustomSHCess,AfterExciseDutySHCess,ExciseDutySHCess, - AfterCustomEdCess,ROUND((Quantity *Rate),2)as TotalOrderValue,ROUND((POMast.ExchangeRate*BasicPriceInMTon),2) as BasicINRValue,TotalValue,CurrencyType,ReceivedQuantity,Tax.*,LineItem.ServiceMaterialDescription, - - Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem - join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO - join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo - left join T_Employee_Details emp on Req.Requestedby = emp.EmpID - - left join T_MRIR_Master Mast on POMast.PONO=Mast.PONO - - left join T_MRIR_Details Det on Det.MaterialCode=LineItem.MaterialCode and Mast.MRIRNO=Det.MRIRNO - - join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode where LineItem.PONO =?'; - //print_r($subQuery); - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - - - - - -function GetCurrencytype() - { - - $subQuery = 'select * from T_Currency_Details'; - - $query = $this->db->query($subQuery); - - return $query->result(); - } - - function GetINRCurrencytype($Currency_Code='') - { - $subQuery='select * from T_Currency_Details where Currency_Code=?'; - $query=$this->db->query($subQuery,array($Currency_Code)); - //print_r($this->db->last_query()); - return $query->result(); - - } - - - - - - - // To Update the PO - function updatePOMaster($PONO,$PODetails) - { - $this->db->where('PONO', $PONO); - $this->db->update('T_PurchaseOrder_Master', $PODetails); - - return TRUE; - } - - - // To update Parent PO as Amended PO - function updateAmendPOMaster($PONO,$PODetail) - { - //echo $PONO."from model"; - - - $this->db->where('PONO', $PONO); - $this->db->update('T_PurchaseOrder_Master', $PODetail); - $insert_id = $this->db->affected_rows(); - - return $insert_id; - } - /** - * This function is used to check the Line Item is already available in the database - * @return array $result : This is result of the query - */ - function LineItemExists($LineItemNo) - { - $this->db->select('LineItemNo,TaxID'); - $this->db->from('T_Service_Tax'); - $this->db->where('LineItemNo ',$LineItemNo ); - //$this->db->where('Requestedby ',$ReqBy ); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - //echo $result->num_rows; - return $query->result_array(); - } - } - /** - * This function is used to check the Revenue Line Item is already available in the database - * @return array $result : This is result of the query - */ - function LineItemExistsinRevenueTax($LineItemNo) - { - $this->db->select('LineItemNo'); - $this->db->from('T_Revenue_Tax'); - $this->db->where('LineItemNo ',$LineItemNo ); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - return $query->result_array(); - } - } - - - function LineItemExistsinImportTax($LineItemNo) - { - $this->db->select('LineItemNo'); - $this->db->from('T_Import_Tax'); - $this->db->where('LineItemNo ',$LineItemNo ); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - return $query->result_array(); - } - } - // To Update the PO Line Item - function updatePOLineItem($PONO,$LineItemNo,$PODetails) - { - $this->db->where('PONO', $PONO); - $this->db->where('LineItemNo', $LineItemNo); - $this->db->update('T_PurchaseOrder_LineItem', $PODetails); - - return TRUE; - } - /*// To Update the Service Tax Item */ - function updateServiceTax($LineItemNo,$PODetails) - { - - $this->db->where('LineItemNo', $LineItemNo); - $this->db->update('T_Service_Tax', $PODetails); - - // print_r($this->db->last_query()); - - return TRUE; - } - - /*// To Update the Revenue Tax Item */ - function updateRevenueTax($LineItemNo,$PODetails) - { - $this->db->where('LineItemNo', $LineItemNo); - $this->db->update('T_Revenue_Tax', $PODetails); - - // print_r($this->db->last_query()); - - return TRUE; - } - - function updateImportTax($LineItemNo,$PODetails) - { - $this->db->where('LineItemNo', $LineItemNo); - $this->db->update('T_Import_Tax', $PODetails); - - // print_r($this->db->last_query()); - - return TRUE; - } - - function getLastInsertedPO() - { - $this->db->select('max(PONO) as PO'); - $this->db->from('T_PurchaseOrderDetails'); - $query = $this->db->get(); - - return $query->result_array(); - } - - - /* This Method to get all the Department name for the requistion */ - function getDepartmentListForAllReq() - { - $subQuery ='SELECT DISTINCT DEPT.DEPCode,DEPT.DepartmentName FROM T_Requestion_Master REQ - JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID - JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode WHERE REQ.Status not in(?,?,?,?)'; - - $query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED)); - //print_r($query); - return $query->result(); - } - /* - This Method to get all department list - */ - function getDepartmentAllList() - { - $subQuery ='SELECT DISTINCT DEPCode,DepartmentName FROM T_DepartmentDetails'; - - $query = $this->db->query($subQuery); - //print_r($query); - return $query->result(); - } - - - function getStatusListforAllReq() - { - $subQuery ='SELECT DISTINCT STAT.StatusCode, STAT.StatusName FROM T_Requestion_Master REQ - JOIN T_Status STAT on REQ.Status = STAT.StatusCode where STAT.StatusCode not in (?,?,?,?)'; - $query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED)); - - // print_r( $this->db->last_query()); - - return $query->result(); - } - - function getStatusByDepartment($DepNo='') - { - - $subQuery ='SELECT DISTINCT STAT.StatusCode ,STAT.StatusName FROM T_Requestion_Master REQ - JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID - JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode - JOIN T_Status STAT ON REQ.Status = STAT.StatusCode - WHERE DEPT.DEPCode=? AND REQ.Status NOT IN (?,?,?,?)'; - $query = $this->db->query($subQuery,array($DepNo,REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED)); - - return $query->result_array(); - } - - function getRequistionListbySearch($Depid='',$Status='',$FromDate='',$ToDate='') - { - $subQuery =' SELECT ReqNo,ReqType,Requestedby,EMP.FirstName,EMP.Designation,STAT.StatusCode ,STAT.StatusName,ReqDate,DEPT.DEPCode,DEPT.DepartmentName FROM T_Requestion_Master REQ - JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID - JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode - JOIN T_Status STAT on REQ.Status = STAT.StatusCode - where REQ.Status NOT IN (?,?,?,?,?)'; - - $appendQuery = $subQuery ; - - if($Depid != '' && $Status != '' && $FromDate != '' && $ToDate != '') - { - $appendQuery .= ' AND DEPT.DEPCode=? AND STAT.StatusCode=? AND ReqDate >= ? AND ReqDate <= ?'; - //echo "$appendQuery";die(); - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$Status,$FromDate,$ToDate)); - //print_r($this->db->last_query()); - return $query->result_array(); - } - else if($Depid != '' && $Status == '' && $FromDate == '' && $ToDate == '') - { - $appendQuery .= ' AND DEPT.DEPCode=?'; - - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid)); - //print_r($this->db->last_query()); - return $query->result_array(); - } - else if($Depid == '' && $Status != '' && $FromDate == '' && $ToDate == '') - { - $appendQuery .= ' AND STAT.StatusCode=?'; - - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Status)); - //print_r($this->db->last_query()); - return $query->result_array(); - } - else if($Depid == '' && $Status == '' && $FromDate != '' && $ToDate != '') - { - $appendQuery .= ' AND ReqDate >= ? AND ReqDate <= ?'; - - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$FromDate,$ToDate)); - //print_r($this->db->last_query()); - return $query->result_array(); - } - else if($Depid != '' && $Status != '' && $FromDate == '' && $ToDate == '') - { - $appendQuery .= ' AND DEPT.DEPCode=? AND STAT.StatusCode=?'; - - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$Status)); - // print_r($this->db->last_query()); - return $query->result_array(); - } - else if($Depid != '' && $Status == '' && $FromDate != '' && $ToDate != '') - { - $appendQuery .= ' AND DEPT.DEPCode=? AND ReqDate >= ? AND ReqDate <= ?'; - - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$FromDate,$ToDate)); - //print_r($this->db->last_query()); - return $query->result_array(); - } - else if($Depid == '' && $Status != '' && $FromDate != '' && $ToDate != '') - { - $appendQuery .= ' AND STAT.StatusCode=? AND ReqDate >= ? AND ReqDate <= ?'; - - $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Status ,$FromDate,$ToDate)); - // print_r($this->db->last_query()); - return $query->result_array(); - } - else - { - $query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED)); - //print_r($this->db->last_query()); - return $query->result(); - } - - } - - function UpdateRequistItemStatus() - { - $query = $this->db->query("update T_Requestion_Details REQ - JOIN T_PurchaseOrder_LineItem line ON REQ.ReqNo = line.ReqNo - JOIN T_PurchaseOrder_Master PO ON PO.PONO = line.PONO - set REQ.Status = CASE WHEN REQ.Quantity = line.Quantity THEN 'ST022' WHEN REQ.Quantity > line.Quantity THEN 'ST023' ELSE 'ST003' END , - REQ.updatedOn= CURRENT_TIMESTAMP - where PO.Status ='".PO_CREATED."'"); - - //$query ->next_result(); - - } - function UpdateRequistionStatus() - { - $result = $this->db-> query("CALL P_UPDATE_REQUISTIONSTATUS_New()") or die(mysql_error()); - - $result ->next_result(); - - } - /** - * This function is used to delete the Line item from details into Database - * @return array $result : This is result of the query - */ - function DeletePOLineItem( $LineItem='',$ReqNo='',$MaterialCode='') - { - $this->db->where('LineItemNo', $LineItem); - $this->db->where('ReqNo', $ReqNo); - $this->db->where('MaterialCode', $MaterialCode); - $this->db->delete('T_PurchaseOrder_LineItem'); - - return TRUE; - } - - /** - * This function is used to delete the Revenue item from details into Database - * @return array $result : This is result of the query - */ - function DeletePORevenueTax( $LineItem='') - { - $this->db->where('LineItemNo', $LineItem); - $this->db->delete('T_Revenue_Tax'); - - return TRUE; - } - - /** - * This function is used to delete Service Tax from details into Database - * @return array $result : This is result of the query - */ - function DeletePOServiceTax( $LineItem='') - { - $this->db->where('LineItemNo', $LineItem); - $this->db->delete('T_Service_Tax'); - - return TRUE; - } - - - function DeletePOImportTax( $LineItem='') - { - $this->db->where('LineItemNo', $LineItem); - $this->db->delete('T_Import_Tax'); - - return TRUE; - } - - /** - * This function is used to get the List of PO details to the approver - * @return array $result : This is result of the query - join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode - */ - function getPOList($type) - { - - $this->db->distinct(); - $this->db->select('mast.PONO,mast.TotalOrderValue,st.StatusCode,st.StatusName,emp.FirstName,mast.CreatedDate,ccm.CostCenterName,ccm.CostCenterCode,mast.POType as RType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,rmast.ReqType,mast.Status,mast.CapitalRange, -(select FirstName from T_Employee_Details where EmpID=EID)as Approver'); - $this->db->from('T_PurchaseOrder_Master mast'); - // $this->db->order_by('mast.Status',"PO_CREATED"); - $this->db->join('T_Status st', 'st.StatusCode=mast.Status'); - - $this->db->join('T_PurchaseOrder_LineItem req', 'req.PONO= mast.PONO'); - $this->db->join('T_Requestion_Master rmast','rmast.ReqNo=req.ReqNo'); - //$this->db->join('T_CostCenter_Budget bud','bud.CostCenterCode = req.CostCenterCode and bud.BudgetType = rmast.ReqType'); - $this->db->join('T_CostCenter_Master ccm','ccm.CostCenterCode = req.CostCenterCode','left'); - $this->db->join('tbl_users tbl', 'rmast.createdby=tbl.userid'); - $this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid'); - $this->db->join('T_DepartmentDetails as Dep','Dep.DEPCode=emp.Departmentcode'); - - if($type=='APPROVAL'){ - $this->db->or_where('mast.Status',PO_CREATED); - $this->db->or_where('mast.Status',PO_APPROVER_ONHOLD); - $this->db->or_where('mast.Status',PO_AWAITING_RELEASE); - $this->db->or_where('mast.Status',PO_RELEASED); - $this->db->or_where('mast.Status',REQITEM_Emergency_PO_CREATED); - $this->db->order_by('mast.Status'); - - } - else if($type=='RELEASE'){ - $this->db->or_where('mast.Status',PO_AWAITING_RELEASE); - $this->db->or_where('mast.Status',PO_RELEASER_ONHOLD); - $this->db->or_where('mast.Status',PO_RELEASED); - $this->db->order_by('mast.Status'); - - - - } - $result=$this->db->get(); - // print_r($this->db->last_query()); - return $result->result(); - - } - - - function UpdatePO($store, $PONO) - { - - $this->db->where('PONO', $PONO); - $this->db->update('T_PurchaseOrder_Master', $store); - - return TRUE; - } - - function GetReleasedDetails($PONO){ - $this->db->select('mast.ReleasedOn,re.FirstName'); - $this->db->from('T_PurchaseOrder_Master mast'); - $this->db->join('tbl_users tbl','mast.ReleasedBy=tbl.userid'); - $this->db->join('T_Employee_Details re','re.EmpID=tbl.EmpID'); - $this->db->where('mast.PONO',$PONO); - $result=$this->db->get(); - //print_r($this->db->last_query()); -//die(); - return $result->result(); - - } - //This is get the capital po list for edit - -function getCapitalPurchaseOrderDetails($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.ServiceMaterialDescription,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency, -Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,Tax.*, - ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,LandingCharge,HighSeasSalesCharge,CustomDuty,ExciseDuty,ExciseDutyEdCess,CustomEdCess,POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,AfterLandingCharge,AfterHighSeasSalesCharge,AfterCustomDuty,AfterExciseDuty,AfterExciseDutyEdCess,AddlExciseDuty,AfterAddlExciseDuty,Grossdutypayable,AvailableModvat,Grossexpensesduetocustomduty,purchaseratePerKG,CustomDutyExpensesPerKG,RMCIncludingCustomersPerKG,QuantityKG,BasicPriceInMTon,ProductPrice,CustomSHCess,AfterCustomSHCess,AfterExciseDutySHCess,ExciseDutySHCess,AfterCustomEdCess,ROUND((POMast.ExchangeRate*BasicPriceInMTon*Quantity),2) as BasicINRValue,Tax.TotalValue as ImportTotalValue,Tax.FreightType,Tax.NoOfTrip,Tax.FreightValue,Tax.AfterFreightValue,POMast.CurrencyType, - - Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem - join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO -join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - - join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo - join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo -left join T_Employee_Details emp on Req.Requestedby = emp.EmpID - - join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode where LineItem.PONO =?'; - //print_r($subQuery); - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - -// This Method to get the Capital PO Details for pdf - function GetCapitalPurchaseOrderDetailsForPDF($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.AmendedDetails as lineamd,ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription, - Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue , - LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,Payment.PaymentID,Payment.PaymentTerms,AdvanceAmount,HSNCODE - FROM T_PurchaseOrder_LineItem LineItem - join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - - join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO - join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID - join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms - left join T_PurchaseOrder_AdvanceRequest Adv on POMaster.PONO=Adv.PONO - where LineItem.PONO =?'; - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - // get requested by details - function GetRequesedByDetails($PONO){ - $this->db->select('mast.CreatedBy,re.FirstName,Dept.DEPCode,Dept.DepartmentName'); - $this->db->from('T_PurchaseOrder_Master mast'); - $this->db->join('tbl_users tbl','mast.CreatedBy=tbl.userid'); - $this->db->join('T_Employee_Details re','re.EmpID=tbl.EmpID'); - $this->db->join('T_DepartmentDetails Dept', 're.Departmentcode = Dept.DEPCode'); - - $this->db->where('mast.PONO',$PONO); - $result=$this->db->get(); - - return $result->result(); - - } - - // get domestic capital po list - - - function getDomesticCapitalPurchaseOrderDetails($PONO = '') - { - - $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.ServiceMaterialDescription,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency, - Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,ROUND((ServiceTax.After_CGST + ServiceTax.After_SGST + ServiceTax.After_IGST),2) as ServiceTaxamount - ,ServiceTax.TotalValue,ServiceTax.CGST,ServiceTax.After_CGST,ServiceTax.SGST,ServiceTax.After_SGST,ServiceTax.IGST,ServiceTax.After_IGST,ServiceTax.otherallowance,ServiceTax.discount,ServiceTax.discountval,ServiceTax.Afterdiscountval, - POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,ROUND((POMast.TotalOrderValue),2) as BasicINRValue,POMast.CurrencyType,FreightType as Ftype,NoOfTrip as NoTrip,FreightValue as Fvalue,AfterFreightValue as Afvalue, - - Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem - join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO - join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode - join T_Service_Tax ServiceTax on ServiceTax.LineItemNo = LineItem.LineItemNo - join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo - join T_Employee_Details emp on Req.Requestedby = emp.EmpID - - join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode where LineItem.PONO =?'; - //print_r($subQuery); - - $query = $this->db->query($subQuery,array($PONO)); - - return $query->result(); - - - } - //get pdf po requistion details - - - function GetPdfRequistionDetails($PONO){ - $this->db->select('LineItem.ReqNo'); - $this->db->from('T_PurchaseOrder_LineItem LineItem'); - $this->db->where('LineItem.PONO',$PONO); - $result=$this->db->get(); - $ReqNo=''; - - foreach ($result->result() as $res){ - - if($ReqNo==$res->ReqNo){ - - } - else{ - $ReqNo = $res->ReqNo; - $this->db->select('ReqMast.ReqNo,ReqMast.CostCenterCode,ReqMast.ReqDate,ReqMast.Schedule_Type,ReqMast.NumberOfService,ReqMast.Service_Period,Dept.DEPCode,Dept.DepartmentName,Dept.shortName'); - $this->db->from('T_Requestion_Master ReqMast'); - - $this->db->join('T_DepartmentDetails Dept', 'ReqMast.RequestedDept = Dept.DEPCode'); - $this->db->where('ReqMast.ReqNo',$ReqNo); - $Reqresult=$this->db->get(); - $Details['RequistionNo']= $Reqresult->result()[0]->ReqNo; - $Detaisl['ReqDate']=$Reqresult->result()[0]->ReqDate; - - $Details['RequestedDept']= $Reqresult->result()[0]->shortName; - $Details['CostCenterCode']= $Reqresult->result()[0]->CostCenterCode; - $date = new DateTime($Reqresult->result()[0]->ReqDate,new DateTimeZone('Asia/Kolkata')); - $retDate = $date->format('d-m-Y'); - $Details['ReqDate']= $retDate; - $ScheduleType = $Reqresult->result()[0]->Schedule_Type; - if($ScheduleType!='Recurring'){ - $Details['Frequency']= $Reqresult->result()[0]->Schedule_Type; - - } - else{ - $Details['Frequency']= $Reqresult->result()[0]->Service_Period.' - '.$Reqresult->result()[0]->NumberOfService; - } - - $ResultArray[]=$Details; - } - - } - - $RequistionDetails = $ResultArray; - return $RequistionDetails; - } - function GetLineItemReceivedQty($ParentPO,$MaterialCode) - { - $this->db->select('ReceivedQuantity'); - $this->db->from('T_PurchaseOrder_LineItem'); - - $this->db->where('PONO',$ParentPO); - $this->db->where('MaterialCode',$MaterialCode); - $result=$this->db->get(); - - return $result->result_array(); - } - - //get paymentTerms details - - function getPaymentTermsDetails($Payment_ID='') - { - - - $getpaymentQuery='select distinct PaymentID,PaymentTerms,Details from T_PaymentTerms'; - $paymentQuery=$this->db->query($getpaymentQuery); - - return $paymentQuery->result(); - - } - /** - * This function is used to get status in status table - - */ - function getStatus($StatusType = '') - { - $this->db->select('StatusCode,StatusName '); - $this->db->from('T_Status'); - $this->db->where('StatusType', $StatusType); - $query = $this->db->get(); - - return $query->result(); - } - - - function edit_mrir($MrirNo) - { - $this->db->distinct(); - $this->db->select('TMM.MRIRNO,TMM.PONO,TMM.IGRNO,TMM.Createdon,TMD.ActualQuantityReceived,IGRM.DeliveryChellanOrInvoiceNo,IGRM.DeliveryChellanDate,IGRM.VehicleNo,IGRM.CourierNo,IGRM.CreatedDate,IGRD.QuantityAsPerInvoice,SUPP.SupplierName,SUPP.Address,POMR.PODate,POMR.DeliveryDate,POMR.ServiceDescription,TMD.MaterialCode,MM.MaterialName,MM.UOM,POLT.Quantity,POLT.ReceivedQuantity,ED.FirstName as PORasiedbyName,ED1.FirstName as MRIRRasiedbyName, ED2.FirstName as IGRRasiedbyName,TMM.MRIRStatus,TMM.Createdon as MRIRCreatedon,POLT.CostCenterCode,CostCenterName,QuantityAccepted,QuantityRejected,TMD.Remarks'); - $this->db->from ('T_MRIR_Master TMM'); - $this->db->join ('T_MRIR_Details TMD','TMM.MRIRNO = TMD.MRIRNO','left');//to get IGRNO,PONO,MRIRNO,mrirdate, - $this->db->join ('T_IGR_Master IGRM', 'IGRM.IGRNO = TMM.IGRNO','left');//to get actualquantity,deliverydate,Invoicedate,vechileno,courierno,igrdate, - $this->db->join ('T_PurchaseOrder_Master POMR ','IGRM.PONO = POMR.PONO','left');//to get podate,deliverydate,servicedescription - $this->db->join ('T_PurchaseOrder_LineItem POLT','IGRM.PONO=POLT.PONO','left');//to get receivedquantity,quantity - - $this->db->join ('T_IGR_Details IGRD','IGRD.IGRNO = IGRM.IGRNO','left');//to get invoicequantity - $this->db->join ('T_MaterialMaster MM','IGRD.MaterialCode = MM.MaterialCode','left'); - $this->db->join ('T_SupplierDetailsN SUPP','POMR.SupplierID = SUPP.SupplierID','left');//to get suppliername,supplieraddress - $this->db->join ('tbl_users user','user.userid = POMR.CreatedBy','left');//to get poraisedby - $this->db->join ('T_Employee_Details ED','ED.EmpID = user.EmpID','left'); - $this->db->join ('tbl_users user1','user1.userid=TMM.CreatedBy','left');//to get mrirraisedby - $this->db->join ('T_Employee_Details ED1','ED1.EmpID = user1.EmpID','left'); - $this->db->join ('tbl_users user2','user2.userid=IGRM.CreatedBy','left');//to get igrraisedby - $this->db->join ('T_Employee_Details ED2','ED2.EmpID = user2.EmpID','left'); - $this->db->join('T_CostCenter_Master TCOST','POLT.CostCenterCode=TCOST.CostCenterCode'); - $this->db->where('TMM.MRIRNO',$MrirNo); - $this->db->group_by('TMM.MRIRNO,TMD.MaterialCode'); - $query = $this->db->get(); - $result = $query->result(); - //print_r( $this->db->last_query()); - return $result; - - } - - - - - - function getadvancePONO($Status='') - { - $this->db->select ('Mast.PONO,POType,Mast.CreatedDate,Mast.ReleasedOn,Mast.TotalOrderValue,Mast.SupplierID,DeliveryDate,DeliverySchedule,DeliveryOption,Mast.PaymentTerms as Paycode,Payterm.PaymentTerms,LineItem.ReqNo,Requestedby,Departmentcode,DepartmentName,LineItem.CostCenterCode,SupDet.SupplierName,Import_DispatchDetails,CurrencyType,AdvancePercentage,AdvanceAmount,POAdv.Remarks,Mast.CapitalRange,Mast.PaymentOtherDescription,RequestedDept'); - $this->db->from('T_PurchaseOrder_Master Mast'); - $this->db->join('T_PurchaseOrder_LineItem LineItem','Mast.PONO=LineItem.PONO'); - $this->db->join('T_Requestion_Master ReqMa','LineItem.ReqNo=ReqMa.ReqNo'); - $this->db->join('T_Employee_Details EmpDet','ReqMa.Requestedby=EmpDet.EmpID','left'); - $this->db->join('T_DepartmentDetails DepDet','EmpDet.Departmentcode=DepDet.DEPCode or ReqMa.RequestedDept=DepDet.DEPCode','left'); - $this->db->join('T_SupplierDetailsN SupDet','Mast.SupplierID=SupDet.SupplierID'); - $this->db->join('T_PurchaseOrder_AdvanceRequest POAdv','Mast.PONO=POAdv.PONO','left'); - $this->db->join('T_PaymentTerms Payterm','Mast.PaymentTerms=Payterm.PaymentID'); - $this->db->where('Mast.Status',$Status); - $query = $this->db->get(); - // print_r($this->db->last_query()); - return $query->result(); - - } - - // update req deatail if work status is completed - - function updateReqDetail($PONO,$POStatus,$MaterialCode) - { - - $this->db->set('Req.Status',$POStatus); - $this->db->where('Item.PONO',$PONO); - $this->db->where('Req.MaterialCode',$MaterialCode); - $this->db->update('T_PurchaseOrder_LineItem Item JOIN T_Requestion_Details Req ON Item.ReqNo= Req.ReqNo'); - return TRUE; - } - - function UpdateReceivedQtyforServicePO($PONO,$updateddt,$updatedBy) - { - $this->db->select('LineItemNo,MaterialCode'); - $this->db->from('T_PurchaseOrder_LineItem'); - $this->db->where('PONO ',$PONO ); - $query = $this->db->get(); - $result = $query->result(); - - if(!empty($result)) - { - foreach ($result as $res) - { - $LineItemNo =$res->LineItemNo; - $MaterialCode = $res->MaterialCode; - //echo $LineItemNo; - - $subQuery = 'update T_PurchaseOrder_LineItem - set ReceivedQuantity=Quantity, status=?,UpdatedOn=?,UpdateBY=? where PONO=? and LineItemNo=?'; - - $query = $this->db->query($subQuery,array(PO_SERVICE_COMPLETED,$updateddt,$updatedBy,$PONO,$LineItemNo)); - $finddot = strpos($PONO,'.'); - if($finddot = true) - { - $subQuery = 'update T_PurchaseOrder_LineItem - set ReceivedQuantity=Quantity, status=?,UpdatedOn=?,UpdateBY=? where PONO=substring(?,1,(case when INstr(?,?) > 0 then INstr(?,?)-1 else 0 end)) and MaterialCode=?'; - - $query = $this->db->query($subQuery,array(PO_SERVICE_COMPLETED,$updateddt,$updatedBy,$PONO,$PONO,'.',$PONO,'.',$MaterialCode)); - } - - } - - } - - } -//get service tax listusing po number - function GetServiceTaxDetails($PONO = ''){ - - $taxQuery ='SELECT group_concat(@count:=@count+1) Itemcode, -st.CGST,st.SGST,st.IGST,st.otherallowance FROM T_Service_Tax st - join T_PurchaseOrder_LineItem pl on pl.LineItemNo=st.LineItemNo - join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO JOIN - (SELECT @count := 0) count - where pm.POType=? and pm.PONO=? - group by st.CGST,st.SGST,st.IGST,st.otherallowance - ORDER BY Itemcode ASC '; - - - $query = $this->db->query($taxQuery,array("SERVICE",$PONO)); - - return $query->result(); - } - // get capital tax listing by po no - - function GetCapitalTaxListDetails($PONO = '',$CapitalRange=''){ - - if($CapitalRange==1){ - $taxQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,SUM(st.`After_CGST`) AS TotalCGST,SUM(st.`After_SGST`) AS TotalSGST,SUM(st.`After_IGST`) AS TotalIGST,SUM(st.`otherallowance`) AS TotalOtherAllowance,SUM(st.`Afterdiscountval`) AS TotalDiscount,st.discountval,st.Afterdiscountval,st.CGST,st.SGST,st.IGST,st.otherallowance,SUM(st.`AfterFreightValue`) AS TotalFreight,st.FreightValue FROM T_Service_Tax st - join T_PurchaseOrder_LineItem pl on pl.LineItemNo=st.LineItemNo - join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO - where pm.POType=? and pm.PONO=? - group by st.Afterdiscountval,st.CGST,st.SGST,st.IGST,st.otherallowance ORDER BY st.LineItemNo ASC'; - $query = $this->db->query($taxQuery,array("CAPITAL",$PONO)); - - return $query->result(); - } - else if($CapitalRange==0){ - $taxQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode, - SUM(it.`AfterFreightValue`) AS TotalFreight,it.FreightValue,it.AfterFreightValue, - it.IGST AS TotalIGSTPer,SUM(it.AfterIGST) as AfterIGST1,it.AfterIGST as AIgst FROM T_Import_Tax it - join T_PurchaseOrder_LineItem pl on pl.LineItemNo=it.LineItemNo - join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO - where pm.POType=? and pm.PONO=? - group by it.AfterFreightValue ORDER BY it.LineItemNo ASC'; - $query = $this->db->query($taxQuery,array("CAPITAL",$PONO)); - - return $query->result(); - } - - } - // get po format for acedamic year based - function GetPoFormat($PONO=''){ - $poQuery ='select PONO from T_PurchaseOrder_Master where PONO=?'; - $query = $this->db->query($poQuery,array($PONO)); - - return $query->result(); -} -//get Dept Emp Name -function getDepartmentEmpList($DepCode=''){ - $this->db->select('EmpID'); - $this->db->from('T_Employee_Details'); - $this->db->where('Departmentcode', $DepCode); - $this->db->limit('1'); - $query = $this->db->get(); - - return $query->result(); -} -//get req master details using reqno -function GetRequistionMasterUsingReqNo($Req){ - - - $this->db->select('Requestedby'); - $this->db->from('T_Requestion_Master'); - $this->db->where('ReqNo', $Req[0]); - $query = $this->db->get(); - - return $query->result(); - - -} -function amendpdf($PONO='') -{ - $Amend ='select p.PONO,p.ParentPO,p.Status,p.TotalOrderValue, - m.Status as parentpostatus, - m.TotalOrderValue as partenttotalorder - from T_PurchaseOrder_Master as p - join T_PurchaseOrder_Master as m - on m.PONO = p.ParentPO - where p.PONO = ?'; - $amendment = $this->db->query($Amend,array($PONO)); - - return $amendment->result(); -} - - - - function GetClients() - { - $this->db->select('client_id,client_name'); - $this->db->from('ip_clients'); - $query = $this->db->get(); - return $query->result_array(); - } - - - function SaveEnquiry($save) - { - $this->db->trans_start(); - $this->db->insert('T_Enquiry', $save); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; - - } - - - function UpdateEnquiry($save,$Id) - { - - $this->db->where('Id',$Id); - $this->db->update('T_Enquiry',$save); - $insert_id = $this->db->affected_rows(); - return $insert_id; - } - - - function GetEnquiryDetails() - { - $this->db->select('T_Enquiry.*,client_name'); - $this->db->from('T_Enquiry'); - $this->db->join('ip_clients','ip_clients.client_id=T_Enquiry.client_id'); - $this->db->order_by('Id','desc'); - $query = $this->db->get(); - return $query->result(); - - } - - - function GetEnquiry($Id) - { - $this->db->select('T_Enquiry.*,client_name'); - $this->db->from('T_Enquiry'); - $this->db->join('ip_clients','ip_clients.client_id=T_Enquiry.client_id'); - $this->db->where('Id',$Id); - $this->db->order_by('Id','desc'); - $query = $this->db->get(); - return $query->result(); - } - - - -function GetEnquiryCount($createddt) -{ - - $this->db->select('count(Id) as Countnumber'); - $this->db->from('T_Enquiry'); - $this->db->where('Created_Date',$createddt); - $query = $this->db->get(); - return $query->result(); -} - - -function SaveActionMaster($master) -{ - - $this->db->trans_start(); - $this->db->insert('T_ActionReport_Master', $master); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - // print_r($this->db->last_query()); - if($insert_id>0) - { - $subQuery = 'select max(Id) as Id from T_ActionReport_Master'; - - $query = $this->db->query($subQuery,array()); - - return $query->result_array(); - } -} - - -function SaveActionDisposition($actionsave) -{ - $this->db->trans_start(); - $this->db->insert('T_Action_Disposition',$actionsave); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; -} - - -function UpdateActionDisposition($actionsave,$LineDisposition) -{ - //echo $LineDisposition; - - $this->db->where('DispositionId', $LineDisposition); - $this->db->update('T_Action_Disposition', $actionsave); - return TRUE; -} - -function UpdateRootCause($rootsave,$Lineroot) -{ - $this->db->where('RootId', $Lineroot); - $this->db->update('T_RootCause', $rootsave); - return TRUE; -} - - -function Updatecounteraction($savecounter,$LineCounter) -{ - $this->db->where('CounterId', $LineCounter); - $this->db->update('T_Action_Counter_Measure', $savecounter); - return TRUE; -} - - -function UpdateActionMaster($master,$Id) -{ - - $this->db->where('Id', $Id); - $this->db->update('T_ActionReport_Master', $master); - $insert_id = $this->db->affected_rows(); - //return TRUE; - if($insert_id>0) - { - $subQuery = 'select max(Id) as Id from T_ActionReport_Master'; - - $query = $this->db->query($subQuery,array()); - - return $query->result_array(); - } -} - - - -function SaveRootCause($rootsave) -{ - - $this->db->trans_start(); - $this->db->insert('T_RootCause',$rootsave); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; - -} - -function Savecounteraction($savecounter) -{ - $this->db->trans_start(); - $this->db->insert('T_Action_Counter_Measure',$savecounter); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; -} - -function GetNcrlist() -{ - $this->db->select('*'); - $this->db->from('T_ComplaintRegister'); - $this->db->join('ip_clients','ip_clients.client_id=T_ComplaintRegister.client_id'); - $this->db->order_by('CId','desc'); - $query = $this->db->get(); - return $query->result(); -} - - -function GetncrmasterDetails($Id) -{ - $this->db->select('*'); - $this->db->from('T_ActionReport_Master'); - $this->db->where('Id',$Id); - $query = $this->db->get(); - return $query->result(); -} - - -function GetDispositionDetails($Id) -{ - $this->db->select('*'); - $this->db->from('T_Action_Disposition'); - $this->db->where('Id',$Id); - $query = $this->db->get(); - return $query->result(); - -} - -function GetRootcauseDetails($Id) -{ - $this->db->select('*'); - $this->db->from('T_RootCause'); - $this->db->where('Id',$Id); - $query = $this->db->get(); - return $query->result(); - -} - -function GetCouteractionDetails($Id) -{ - - $this->db->select('*'); - $this->db->from('T_Action_Counter_Measure'); - $this->db->where('Id',$Id); - $query = $this->db->get(); - return $query->result(); -} - - - -function Savecomplaint($save_complaint) -{ - $this->db->trans_start(); - $this->db->insert('T_ComplaintRegister',$save_complaint); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; -} - - -function Get_SavedComplaint($CId) -{ - $this->db->select('*'); - $this->db->from('T_ComplaintRegister'); - $this->db->join('ip_clients','ip_clients.client_id=T_ComplaintRegister.client_id'); - $this->db->where('CId',$CId); - $this->db->order_by('CId','desc'); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); -} - -function Updatecomplaint($save_complaint,$CId) -{ - - $this->db->where('CId', $CId); - $this->db->update('T_ComplaintRegister', $save_complaint); - return TRUE; -} - -function updatecomplaintId($up,$CId) -{ - $this->db->where('CId', $CId); - $this->db->update('T_ComplaintRegister',$up); - return TRUE; -} - - -function GetActionid($LineDisposition) -{ - - $this->db->select('*'); - $this->db->from('T_Action_Disposition'); - $this->db->where('DispositionId',$LineDisposition); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); -} - - - -function GetlastDispositionId() -{ - $subQuery = 'select max(DispositionId) from T_Action_Disposition'; - - $query = $this->db->query($subQuery,array()); - - return $query->result_array(); -} - - - -function Getrootid($Lineroot) -{ - $this->db->select('*'); - $this->db->from('T_RootCause'); - $this->db->where('RootId',$Lineroot); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); -} - - - -function Getcounterid($LineCounter) -{ - $this->db->select('*'); - $this->db->from('T_Action_Counter_Measure'); - $this->db->where('CounterId',$LineCounter); - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); -} - - -function DeleteAction($DelId) -{ - $this->db->where('DispositionId', $DelId); - $this->db->delete('T_Action_Disposition'); - //print_r($this->db->last_query()); - return TRUE; -} - - -function DeleteRoot($DelId) -{ - $this->db->where('RootId', $DelId); - $this->db->delete('T_RootCause'); - //print_r($this->db->last_query()); - return TRUE; -} - - -function DeleteCounter($DelId) -{ - $this->db->where('CounterId', $DelId); - $this->db->delete('T_Action_Counter_Measure'); - //print_r($this->db->last_query()); - return TRUE; -} - - -/*------------------------------------------------------------------------------*/ - -function updatefile($bill,$Picture,$oldfile) -{ - - // if($oldfile != ''){ - // //unlink("uploads/BillFiles/".$oldfile);//this deletes the file on particular folder too - // } - -$this->db->set('FilePath', $Picture); //value that used to update column -$this->db->where('BillNo', $bill); //which row want to upgrade -$this->db->update('T_PurchaseOrder_BillUpload'); -$afftectedRows = $this->db->affected_rows(); -return $afftectedRows; - -} - - - -// function newlogpo($logpo) -// { - -// $this->db->trans_start(); -// $this->db->insert('T_ponewlogs_Details',$logpo); -// $insert_id = $this->db->affected_rows(); -// $this->db->trans_complete(); -// return $insert_id; - - -// // $this->db->trans_start(); -// // $this->db->insert('T_polog_Details',$logpo); -// // $insert_id = $this->db->affected_rows(); -// // $this->db->trans_complete(); -// // return $insert_id; - -// } - - - -function insertlogpo($logpo){ - - - - - // $this->db->where('MaterialCode',$MaterialCode,'LineItemNos',$POLineItemNo); - // $this->db->update('T_ponewlogs_Details',$logpo); - $this->db->trans_start(); - $this->db->insert('T_polog_Details',$logpo); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - return $insert_id; - -} -function getlogpodtl($PONO){ - - - - - - -// $SQL = "select distinct log.PONO as LPONO, -// case -// WHEN log.Quantity <> pl.Quantity THEN log.Quantity -// else '-' -// ENd as Lqty, - -// case -// WHEN log.SupplierID <> pm.SupplierID THEN sup.Suppliername -// else '-' -// ENd as LSuppid, -// case -// WHEN log.Date <> pm.PODate THEN log.Date -// else '-' -// ENd as logDate , -// case -// WHEN log.Rate <> pl.Rate THEN log.Rate -// else '-' -// ENd as logRate , - - -// log.LineItemNos,log.MaterialCode,log.UpdatedOn,log.UpdateBy,emp.FirstName - - -// from T_ponewlogs_Details log -// join T_PurchaseOrder_LineItem pl on log.LineItemNos = pl.LineItemNo -// join T_PurchaseOrder_Master pm on pm.PONO = log.PONO -// join tbl_users user on user.userId = log.UpdateBy -// left join T_Employee_Details emp on emp.EmpID= user.EmpID -// left join T_SupplierDetailsN sup on sup.SupplierID = log.SupplierID -// where log.PONO ='".$PONO."'"; - - - -$SQL = "select log.*,sup.SupplierName,emp.FirstName from - T_polog_Details log - join tbl_users user on user.userId = log.UpdateBy - left join T_Employee_Details emp on emp.EmpID= user.EmpID - left join T_SupplierDetailsN sup on sup.SupplierID = log.oldValue - where PONO ='".$PONO."'"; - - -$logpodtl = $this->db->query($SQL); - - return $logpodtl->result(); -} - - - // function EditpoValues($pono) - // { - // $this->db->select('*'); - // $this->db->from('T_ponewlogs_Details'); - // $this->db->where('PONO',$pono); - // // $this->db->where('MaterialCode',$materialcode); - // $query = $this->db->get(); - // return $query->result_array(); - // } - - - function insertfile($filelist) - { - - //print_r($myfile);die; - - $this->db->insert('T_PurchaseOrder_BillUpload',$filelist); - $myfile=$this->db->affected_rows(); - return $myfile; - } - -/*------------------------------------------------------------------------------*/ - -function updateigrM($PONO,$IGRNo,$igrMaster){ - - //print_r($igrMaster);die; - $this->db->where('PONO',$PONO); - $this->db->where('IGRNO',$IGRNo); - - $this->db->update('T_IGR_Master',$igrMaster); - - $r = $this->db->affected_rows(); - return $r; -} -function getigrno($bill){ - - $subQuery ='select bill.BillNo,IGR.IGRNO, IGR.PONO FROM T_IGR_Master IGR - join T_PurchaseOrder_BillUpload bill on bill.IGRNO = IGR.IGRNO - where bill.BillNO = ? '; - - $query = $this->db->query($subQuery,array($bill)); - - return $query->result_array(); - } - /*** ----------------------------- */ +db->distinct(); + $this->db->select('PO.PONO'); + $this->db->from('T_PurchaseOrder_Master PO'); + $this->db->join('T_PurchaseOrder_LineItem Line','PO.PONO = Line.PONO'); + $this->db->join('T_Requestion_Master Req','Req.ReqNo = Line.ReqNo'); + + $this->db->where('PO.POType',SERVICE); + $this->db->where('PO.status',PO_RELEASED); + $this->db->where('Req.RequestedDept',$this->session->userdata('DEPCode')); + + + + $query = $this->db->get(); + // print_r( $this->db->last_query()); + return $query->result(); + } + + + + +/*------------jun15------------------*/ + + +function getfies($pono) + { + + $this->db->select('*'); + + + $this->db->from('T_PurchaseOrder_BillUpload bill'); + + $this->db->where('PONO',$pono); + + $query = $this->db->get(); + + return $query->result(); + } +/*-----------jun15-------------------*/ + + + function updateMatStock($itemNo, + $MaterialstockHistoryupdate){ + //echo'hi'; + + + $this->db->where('Ref_No',$itemNo); + $this->db->update('T_Material_stock_history', $MaterialstockHistoryupdate); + + $r = $this->db->affected_rows(); + return $r; +} + + + + +function updateReqDetails($Reqnumber,$MaterialCode,$ReqDetail){ + //echo'hi'; + + $this->db->where('ReqNo',$Reqnumber); + $this->db->where('MaterialCode',$MaterialCode); + // $this->db->where('Quantity',$Quantity); + + $this->db->update('T_Requestion_Details',$ReqDetail); + + $r = $this->db->affected_rows(); + return $r; +} + + +function IGRDetailsupdate($PONO) +{ + //echo 'hi'; + + + $subQuery ='select IGRM.PONO,IGRD.IGRItemNo,IGRD.IGRNO from +T_IGR_Master IGRM +join T_IGR_Details IGRD on IGRD.IGRNO = IGRM.IGRNO +Where IGRM.PONO = ? '; + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result_array(); + + + } + + + function updateIGR($IGRItemNo,$IGRDs) //,$MaterialCode, + { + //print_r(array($IGRDs,$IGRItemNo)); + + $this->db->where('IGRItemNo',$IGRItemNo); //,'IGRNO',$IGRNO,'MaterialCode',$MaterialCode); + //$this->db->where('IGRNO',$IGRNO); + // $this->db->where('MaterialCode',$MaterialCode); + $this->db->update('T_IGR_Details',$IGRDs); + + $r = $this->db->affected_rows(); + + // $this->db->last_query(); + + return $r; + + + + + + + } + + + + + +/*------------------------------*/ + + + /////////////////// start this function used to pono reset financeyear configuration + + function ponoreset($ponoreset) + { + + //print_r($ponoreset); die; + $this->db->insert('T_PONO_Reset_Table',$ponoreset); + + $r = $this->db->affected_rows(); + return $r; + } + + + function updateponoreset($ponoreset,$sno,$potype,$posubtype) +{ + + + $this->db->where('reset_pono_id',$sno,'POType',$potype,'POSubtype',$posubtype); + $this->db->update('T_PONO_Reset_Table',$ponoreset); + $r = $this->db->affected_rows(); + return $r; + +} + + function ponoresetfinyear() + { + $this->db->select('*'); + $this->db->from('T_PONO_Reset_Table'); + $query =$this->db->get(); + return $query->result(); + } + ///////////////////end this function used to pono reset financeyear configuration + + + + + function fileupload($myfile) + { + + //print_r($myfile);die; + + $this->db->insert('T_PurchaseOrder_BillUpload',$myfile); + $myfile=$this->db->affected_rows(); + return $myfile; + } + + /*--------------------------------------------------*/ +/* this function used parendpo igr values get inward report display */ +function updateigrmaster($igrno,$NewPOno) +{ + // $this->db->insert('T_IGR_Master',$IGRaddvalues); + // $myfile=$this->db->affected_rows(); + // return $myfile; + + $this->db->where('IGRNO',$igrno); + $this->db->update('T_IGR_Master',$NewPOno); + $insert_id = $this->db->affected_rows(); + return $insert_id; +} +function updateigrfile($igrno,$NewPOno) +{ + $this->db->where('IGRNO',$igrno); + $this->db->update('T_Inwardgateregister_fileupload',$NewPOno); + $insert_id = $this->db->affected_rows(); + return $insert_id; + +} + +function selectigrmaster($PONO) +{ + +$this->db->select('*'); +$this->db->from('T_IGR_Master'); +$this->db->where('PONO',$PONO); + $query = $this->db->get(); + return $query->result(); + +} + + + +function getpolineqty($NewPO) +{ + $this->db->select('sum(Quantity)as Qty,sum(ReceivedQuantity)as rec'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO',$NewPO); + + $query = $this->db->get(); + return $query->result(); +} + + +function POLineItemsupdatestatus($NewPO,$Newstatus) +{ + $this->db->where('PONO',$NewPO); + $this->db->update('T_PurchaseOrder_LineItem',$Newstatus); + $update = $this->db->affected_rows(); + return $update; + +} + +function pomasterupdatestatus($NewPO,$Newstatus) +{ + $this->db->where('PONO',$NewPO); + $this->db->update('T_PurchaseOrder_Master',$Newstatus); + $update = $this->db->affected_rows(); + return $update; +} + + +/*--------------------------------------------------*/ + + + + + function getfunction($pono) + { + $this->db->distinct(); + $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType'); + $this->db->from('T_PurchaseOrder_BillUpload bill'); + $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left'); + $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); + // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); + $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO'); + $this->db->where('bill.PONO',$pono); + //$this->db->or_where('pom.status',SPECIAL_PO); + $this->db->group_by('bill.BillNo'); + + + + + +// $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo, +// mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate, +// mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType'); + +// $this->db->from('T_IGR_Master mstr'); +// $this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left'); +// $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); +// // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); +// $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO'); +// $this->db->where('mstr.PONO',$pono); + + $query = $this->db->get(); + + return $query->result(); + } + +function getfunctionr($pono) + { + $this->db->distinct(); + // $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType'); + // $this->db->from('T_PurchaseOrder_BillUpload bill'); + // $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left'); + // $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); + // // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); + // $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO'); + // $this->db->where('bill.PONO',$pono); + // //$this->db->or_where('pom.status',SPECIAL_PO); + // $this->db->group_by('bill.BillNo'); + + + + + + $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo, +mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate, +mstr.CourierNo,pom.Status,pom.POType'); //,bill.BillNo,bill.FilePath, + + $this->db->from('T_IGR_Master mstr'); + //$this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left'); + $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); + // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); + $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO'); + $this->db->where('mstr.PONO',$pono); + + $query = $this->db->get(); + + return $query->result(); + } + + +function getbillfiesr($pono) + { + $this->db->distinct(); + // $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType'); + // $this->db->from('T_PurchaseOrder_BillUpload bill'); + // $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left'); + // $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); + // // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); + // $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO'); + // $this->db->where('bill.PONO',$pono); + // //$this->db->or_where('pom.status',SPECIAL_PO); + // $this->db->group_by('bill.BillNo'); + + + + + + $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo, +mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate, +mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType'); + + $this->db->from('T_IGR_Master mstr'); + $this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left'); + $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left'); + // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode'); + $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO'); + $this->db->where('mstr.PONO',$pono); + + $query = $this->db->get(); + + return $query->result(); + } + + + + function GetPODetailforBillingServicePO($PONO) + { + + $subQuery ='select mast.ReqNo,mast.ReqDate,supp.SupplierName,PODate,st.StatusName as WorkStatus,ServiceWorkStatus,POMast.PaymentTerms, + POMast.ServiceWorkStatus,LineItem.*,mat.MaterialName,mat.UOM,emp.FirstName,emp.LastName,POMast.TotalOrderValue + from T_PurchaseOrder_Master POMast + join T_PurchaseOrder_LineItem LineItem on LineItem.PONO = POMast.PONO + join T_SupplierDetailsN supp on supp.SupplierID = POMast.SupplierID + join T_MaterialMaster mat on mat.MaterialCode = LineItem.MaterialCode + join T_Status Stat on Stat.StatusCode = POMast.Status + join T_Status st on st.StatusCode = POMast.ServiceWorkStatus + join T_Requestion_Master mast on mast.ReqNo = LineItem.ReqNo + join tbl_users users on users.userId = mast.CreatedBy + join T_Employee_Details emp on emp.EmpID = users.EmpID + where POMast.POType=? and POMast.PONO=?'; + + $query = $this->db->query($subQuery,array(SERVICE,$PONO)); + + return $query->result_array(); + + } + + function GetServicePOListforBilling() + { + $subQuery ='select POMast.PONO,supp.SupplierName,PODate,POMast.PaymentTerms,POMast.ServiceWorkStatusRemarks,StatusName,POMast.CapitalRange,POType, + LineItem.*,mat.MaterialName,mat.UOM,emp.FirstName,emp.LastName,Tax.TotalValue,Cost.CostCenterName,AdvanceAmount + ,Dept.DepartmentName from T_PurchaseOrder_Master POMast + join T_PurchaseOrder_LineItem LineItem on LineItem.PONO = POMast.PONO + join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + left join T_PurchaseOrder_AdvanceRequest PUADV on POMast.PONO=PUADV.PONO + join T_SupplierDetailsN supp on supp.SupplierID = POMast.SupplierID + join T_MaterialMaster mat on mat.MaterialCode = LineItem.MaterialCode + join T_Status Stat on Stat.StatusCode = POMast.Status + join T_Requestion_Master mast on mast.ReqNo = LineItem.ReqNo + join tbl_users users on users.userId = POMast.CreatedBy + left join T_Employee_Details emp on emp.EmpID = mast.Requestedby + join T_DepartmentDetails Dept on Dept.DEPCode = mast.RequestedDept + join T_CostCenter_Master Cost on Cost.CostCenterCode=LineItem.CostCenterCode + where POMast.POType=? and ServiceWorkStatus=? order by POMast.UpdatedOn desc'; + + $query = $this->db->query($subQuery,array(SERVICE,SERVICE_COMPLETED)); + + //print_r( $this->db->last_query()); + return $query->result(); + + } + + /** + * This function is used to get the user listing count + * @param string $searchText : This is optional search text + * @return number $count : This is row count + */ + function purchaseorderListingCount() + { + $this->db->distinct(); + $this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Req.ReqType,DeliveryDate'); + $this->db->from('T_PurchaseOrder_Master POMast'); + $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID'); + $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status'); + $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO'); + $this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo'); + // print_r( $this->db->last_query()); + $query = $this->db->get(); + + return count($query->result()); + } + + /** + * This function is used to get the user listing count + * @param string $searchText : This is optional search text + * @param number $page : This is pagination offset + * @param number $segment : This is pagination limit + * @return array $result : This is result + */ + +function purchaseorderListing($forwhat='') + { + $this->db->distinct(); + $this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Stat.StatusCode,POMast.POType as ReqType,DeliveryDate,DeliverySchedule,DeliveryOption,POMast.CapitalRange,POMast.UpdatedOn'); + $this->db->from('T_PurchaseOrder_Master POMast'); + $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID'); + $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status'); + $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO'); + $this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo'); + if($forwhat=='amendment') + { + $this->db->where('POMast.Status',PO_RELEASED); + } + else + { + $this->db->where('POMast.Status !=',PO_AMENDED); + // $this->db->order_by('POMast.Status !=',PO_AMENDED); + } + $this->db->order_by('POMast.UpdatedOn','desc'); + $query = $this->db->get(); + //print_r( $this->db->last_query()); + $result = $query->result(); + return $result; + } + + /** + * This function is used to get the SupplierID and SupplierName information + * @return array $result : This is result of the query + */ + function getSupplierName($supID='') + { + $this->db->select('SupplierID, SupplierName,Address,PaymentID'); + $this->db->from('T_SupplierDetailsN'); + $this->db->where('IsActive', 1); + if($supID != '') + { + $this->db->where('SupplierID',$supID); + } + //$this->db->where('roleId !=', 1); + $query = $this->db->get(); + + return $query->result(); + } + /** + * This function is used to get the userId information + * @return array $result : This is result of the query + */ + function getusers() + { + $this->db->select('userId, name'); + $this->db->from('tbl_users'); + //$this->db->where('roleId !=', 1); + $query = $this->db->get(); + + return $query->result(); + } + + + function getqtycheck($PONO) + { + $this->db->select('IsQualityChkReqired'); + $this->db->from('T_PurchaseOrder_Master'); + $this->db->where('PONO',$PONO); + $query = $this->db->get(); + + return $query->result(); + + } +/** + * This function is used to get the Raw Material information + * @return array $result : This is result of the query + */ + function getRawPOMaterialList($ReqNo,$IsArray='') + { + + $result = $this->db-> query("CALL P_GET_REQUISTIONLIST('".$ReqNo."')") or die(mysql_error()); + + $result ->next_result(); + + //print_r($this->db->last_query()); + + if ($result->num_rows > 0) + { + //echo 'PO Line item Inserted successfully'; + if($IsArray != '') + { + return $result->result_array(); + } + else + { + return $result->result(); + } + } + + } + + /** + This Function to get the List of Requistion which require to create PO + */ + function getAllRequistionListToCreatePO() + { + $result = $this->db-> query("CALL P_PURCHASEORDER_DETAILS()") or die(mysql_error()); + + $result ->next_result(); + + + if ($result->num_rows > 0) + { + + return $result->result(); + } + } + + /** + * This function is used to get the Raw Material information + * @return array $result : This is result of the query + */ + function getRawMaterialList($MatType='',$ReqNoList='') + { + + $this->db->select('ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity'); + $this->db->from('T_Requestion_Details Req'); + $this->db->join('T_MaterialMaster mat', 'Req.MaterialCode = mat.MaterialCode'); + $this->db->where('mat.MaterialType', $MatType); + $this->db->where_in('Req.ReqNo', $ReqNoList); + + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); + } + /** + * This function is used to get the Raw Material information + * @return array $result : This is result of the query + */ + function getRawMaterialListForPO($MatType='',$ReqNo='') + { + $subQuery ='SELECT ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity + FROM T_Requestion_Details Req + JOIN T_MaterialMaster mat ON Req.MaterialCode = mat.MaterialCode + where mat.MaterialType = ? + AND Req.ReqNo = ? + AND mat.MaterialCode != (SELECT MaterialCode FROM T_PurchaseOrder_LineItem WHERE ReqNo =? + )'; + + $query = $this->db->query($subQuery,array($MatType,$ReqNo,$ReqNo)); + + return $query->result_array(); + + + } + //Import PO Available Budget Amount + function GetAvailableImportBudgetAmount($CostCode,$Year,$BudgetType) + { + $subQuery='select BudgetAmount,(select ifnull(sum((Quantity*Rate*ExchangeRate)),0)as TValue from T_PurchaseOrder_LineItem LineItem + join T_PurchaseOrder_Master Mast on Mast.PONO=LineItem.PONO where POType=? + and CostCenterCode=? and Mast.status not in (?) )as Totalvalue from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and BudgetYear=? and BudgetType=?'; + $query = $this->db->query($subQuery,array($BudgetType,$CostCode,PO_AMENDED,$CostCode,$Year,$BudgetType)); + //print_r($this->db->last_query()); + return $query->result_array(); + + + } + //get available budget for capital + function GetAvailableCapitalBudgetAmount($CostCode,$Year,$BudgetType) + { + + $subQuery ='select BudgetAmount, (select ifnull(sum(IF(POMaster.ExchangeRate>0,Quantity*Rate*POMaster.ExchangeRate,Quantity*Rate-tax.Afterdiscountval)),0) as Totalvalue from + T_PurchaseOrder_LineItem Item join T_Requestion_Master mast + on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POMaster on POMaster.PONO=Item.PONO left join T_Service_Tax tax on tax.LineItemNo=Item.LineItemNo where Item.CostCenterCode=? and POMaster.POType=? and POMaster.status not in (?))as Totalvalue + from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and + BudgetYear = ? and BudgetType =?'; + + $query = $this->db->query($subQuery,array($CostCode,$BudgetType,PO_AMENDED,$CostCode,$Year,$BudgetType)); + + return $query->result_array(); + + } + function GetAvailableBudgetAmount($CostCode,$Year,$BudgetType) + { + $subQuery ='select distinct Bud.CostCenterCode,BudgetAmount, case WHEN BudgetType = ? then (select + round(ifnull(sum((Quantity*Rate)-ifnull(tax.AfterDiscount,0)),0),2) as + Totalvalue from T_PurchaseOrder_LineItem Item join T_Requestion_Master mast + on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POM on POM.PONO = Item.PONO left join T_Revenue_Tax tax on + tax.LineItemNo = Item.LineItemNo + where Item.CostCenterCode=? and POM.POType=? and POM.status not in (?)) else (select + round(ifnull(sum(Quantity*Rate*ifnull(case when mast.NumberOfService=? + then 1 else mast.NumberOfService end ,1)),0),2) as + Totalvalue from T_PurchaseOrder_LineItem Item join T_Requestion_Master mast + on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POM on POM.PONO = Item.PONO left join T_Requestion_Master ReqMas on ReqMas.ReqNo= Item.ReqNo + where Item.CostCenterCode=? and POM.POType=? and POM.status not in (?) ) end as Totalvalue + from T_CostCenter_Budget Bud join T_CostCenter_Departments dept on dept.CostCenterCode = Bud.CostCenterCode + where Bud.CostCenterCode=? and + BudgetYear = ? and BudgetType =?'; + + + $query = $this->db->query($subQuery,array(REVENUE,$CostCode,$BudgetType,PO_AMENDED,'0.00',$CostCode,$BudgetType,PO_AMENDED,$CostCode,$Year,$BudgetType)); + + + //print_r($this->db->last_query()); + return $query->result_array(); + + } + + //to get POTYpe from ReqNo +function GetPOType($ReqNo) +{ + $this->db->select('POType'); + $this->db->from('T_PurchaseOrder_Master mast'); + $this->db->join('T_PurchaseOrder_LineItem Line', 'mast.PONO=Line.PONO'); + $this->db->where('Line.ReqNo', $ReqNo); + $query = $this->db->get(); + return $query->result_array(); +} + + /** + * This function is used to get the Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistDetails($ReqNoList='') + { + $ReqDeatis = $this->GetRequistionMasterUsingReqNo($ReqNoList); + + foreach ($ReqDeatis as $SID): + $ReqBy = $SID->Requestedby ; + + endforeach; + if($ReqBy=='' || $ReqBy==null){ + $this->db->distinct(); + $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,mast.Schedule_Type,mast.NumberOfService,mast.Service_Period, + Dept.DEPCode,Dept.DepartmentName,mast.ReqDate,mast.CostCenterCode,mast.Status'); + $this->db->from('T_Requestion_Master mast'); + + $this->db->join('T_DepartmentDetails Dept', 'mast.RequestedDept = Dept.DEPCode'); + $this->db->where_in('mast.ReqNo', $ReqNoList); + } + + else if($ReqBy!='') { + $this->db->distinct(); + $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,mast.Schedule_Type,mast.NumberOfService,mast.Service_Period,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate,mast.CostCenterCode,mast.Status'); + $this->db->from('T_Requestion_Master mast'); + $this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID'); + $this->db->join('T_DepartmentDetails Dept', 'mast.RequestedDept = Dept.DEPCode'); + $this->db->where_in('mast.ReqNo', $ReqNoList); + } + + + $query = $this->db->get(); + + return $query->result(); + } + /** + * This function is used to get the Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistDetailsForPO($ReqNoList='') + { + $this->db->distinct(); + $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate'); + $this->db->from('T_Requestion_Master mast'); + $this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID'); + $this->db->join('T_DepartmentDetails Dept', 'emp.Departmentcode = Dept.DEPCode'); + $this->db->where_in('mast.ReqNo', $ReqNoList); + + $query = $this->db->get(); + + return $query->result(); + } + /** + * This function is used to get the Cost center information + * @return array $result : This is result of the query + */ + function getCostCenter() + { + + $this->db->select('CostName, Description'); + $this->db->from('T_CostCentre'); + + $query = $this->db->get(); + + return $query->result(); + } + + + /** + * This function is used to get the CostCenter for the Selected Requistion Number + * @return array $result : This is result of the query + */ + function getCostCenterbyRequist($ReqNo='',$BudYear='',$ReqType='') + { + + $this->db->distinct(); + $this->db->select('Mast.CostCenterCode,Mast.CostCenterName,Bud.BudgetAmount,ReqNo'); + $this->db->from('T_CostCenter_Master Mast'); + $this->db->join('T_CostCenter_Departments CostDept', 'CostDept.CostCenterCode = Mast.CostCenterCode'); + $this->db->join('T_CostCenter_Budget Bud', 'Bud.CostCenterCode = Mast.CostCenterCode'); + $this->db->join('T_Employee_Details emp', 'CostDept.DEPCode = emp.Departmentcode'); + $this->db->join('T_Requestion_Master req', 'req.Requestedby = emp.EmpID'); + + $this->db->where('BudgetType ',$ReqType ); + $this->db->where('BudgetYear ',$BudYear ); + if($ReqNo != '') + { + $this->db->where('ReqNo ',$ReqNo); + } + + $query = $this->db->get(); + return $query->result(); + } + +/** + * This function is used to get the Config value from configuration table + * @return array $result : This is result of the query + */ + function getRequistionNoFromPO($PONO='') + { + $this->db->distinct(); + $this->db->select('ReqNo,'); + $this->db->from('T_PurchaseOrder_LineItem'); + if($PONO != '') + { + $this->db->where('PONO ',$PONO ); + } + + $query = $this->db->get(); + + return $query->result(); + } + + + /** + * This function is used to get the Config value from configuration table + * @return array $result : This is result of the query + */ + function getConfigValue($ConfigID ,$ConfigValue = '') + { + + $this->db->select('ConfigValue'); + $this->db->from('T_ConfigDetails'); + $this->db->where('Config_id ',$ConfigID ); + if($ConfigValue != '') + { + $this->db->where('ConfigValue != ',$ConfigValue ); + } + $query = $this->db->get(); + + return $query->result(); + } + + + + + /** + * This function is used to get the Company information from T_Company_Details table + * @return array $result : This is result of the query + */ + function getCompanyInformation() + { + + $subQuery = "select CompanyName,replace(Address,'
    ','') as Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode + from T_Company_Details "; + + + + $query = $this->db->query($subQuery); + + + //print_r($this->db->last_query()); + return $query->result(); + // return $query->result(); + } + /** + * This function is used to get the Company information from T_Company_Details table + * @return array $result : This is result of the query + */ + function getCompanyInformationforPDF() + { + + $subQuery = "select CompanyName,Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode + from T_Company_Details "; + + + + $query = $this->db->query($subQuery); + + + //print_r($this->db->last_query()); + return $query->result(); + // return $query->result(); + } + + /** + * This function is used to get the Employee List + * @return array $result : This is result of the query + */ + function getAllEmployees() + { + $this->db->select('EmpID,FirstName,LastName'); + $this->db->from('T_Employee_Details'); + $query = $this->db->get(); + + return $query->result(); + } + + /** + * This function is used to get the Employee List + * @return array $result : This is result of the query + */ + function getLastCreatedPODate() + { + $this->db->select('max(PODate) as PODate'); + $this->db->from('T_PurchaseOrder_Master'); + $query = $this->db->get(); + + return $query->result(); + } + + function getLastReleasedPODate() + { + $this->db->select('max(ReleasedOn) as PODate'); + $this->db->from('T_PurchaseOrder_Master'); + $query = $this->db->get(); + + return $query->result(); + } + /** + * This function is used to add New Purchase order to the system + + */ + function addPOMaster($POMaster,$POType,$POSubtype) + { + $this->db->trans_start(); + $this->db->insert('T_PurchaseOrder_Master', $POMaster); + //$this->db->update('T_PONO_Reset_Table') + + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + if($insert_id>0) + { + $subQuery = 'select PONO from T_PurchaseOrder_Master where POType=? and POSubType=? and isnull(ParentPO) order by CreatedDate desc limit 1 '; + + $query = $this->db->query($subQuery,array($POType,$POSubtype)); + + //print_r($query->result());die(); + return $query->result_array(); + } + } + + + + + + function addAmendPOMaster($POMaster,$CreatedBy,$ParentPO) + { + // print_r($POMaster); + $this->db->trans_start(); + $this->db->insert('T_PurchaseOrder_Master', $POMaster); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + if($insert_id>0) + { + $subQuery = 'select PONO from T_PurchaseOrder_Master where CreatedBy=? and ParentPO=? order by CreatedDate desc limit 1'; + + $query = $this->db->query($subQuery,array($CreatedBy,$ParentPO)); + + return $query->result_array(); + } + } + + /** + * This function is used to add New Purchase order Line Item to the system + */ + function addPOLineItem($POLineItem) + { + $this->db->trans_start(); + $this->db->insert('T_PurchaseOrder_LineItem', $POLineItem); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + if($insert_id>0) + { + // $subQuery = 'select max(LineItemNo) as LineItemNo from T_PurchaseOrder_LineItem'; + $subQuery = 'SELECT * FROM T_PurchaseOrder_LineItem where PONO = "'.$POLineItem['PONO'].'" ORDER BY LineItemNo DESC'; + + $query = $this->db->query($subQuery); + + return $query->result_array(); + } + } + + /** + * This function is used to add Revenue Tax to the system + */ + function addRevenueTax($RevenueTaxList) + { + $this->db->trans_start(); + $this->db->insert('T_Revenue_Tax', $RevenueTaxList); + $this->db->trans_complete(); + $insert_id = $this->db->insert_id(); + $aff_row = $this->db->affected_rows(); + // print_r( $this->db->last_query()); die(); + // echo "aff_row".$aff_row." $insert_id".$insert_id; + return $aff_row > 0 ? $this->db->insert_id() : 0; + } + /** + * This function is used to add Service Tax to the system + */ + function addServiceTax($ServiceTaxList) + { + $this->db->trans_start(); + $this->db->insert('T_Service_Tax', $ServiceTaxList); + $this->db->trans_complete(); + $insert_id = $this->db->affected_rows(); + return $insert_id>0 ? $this->db->insert_id() : 0; + } + + + /** + * This function is used to add Service Tax to the system + */ + function addImportTax($ImportTaxList) + { + $this->db->trans_start(); + $this->db->insert('T_Import_Tax', $ImportTaxList); + $this->db->trans_complete(); + $insert_id = $this->db->affected_rows(); + return $insert_id>0 ? $this->db->insert_id() : 0; + } + + + + function addadvanceRequest($advance) + { + $this->db->trans_start(); + $this->db->insert('T_PurchaseOrder_AdvanceRequest', $advance); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; + + + } + + function PONOExists($PONO) + { + + $this->db->select('PONO'); + $this->db->from('T_PurchaseOrder_AdvanceRequest'); + $this->db->where('PONO ',$PONO); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + return $query->result_array(); + } + + + } + + + + function updateadvanceRequest($advance,$PONO) + { + $this->db->where('PONO', $PONO); + $this->db->update('T_PurchaseOrder_AdvanceRequest',$advance); + $insert_id = $this->db->affected_rows(); + return $insert_id; + } + + + /** + * This function used to get user information by id + * @param number $userId : This is user id + * @return array $result : This is user information + */ + function getuserInfo($PO) + { + $this->db->select('POType, PODate, SupplierID,SpecialOrder,UserID,RequestedDate,RequesterEmail,RequesterPh, PurchasingCategory,BudgetManager,BudgetManagerDepartment,'); + $this->db->from('T_PurchaseOrderDetails'); + $this->db->where('PONO', $PO); + $query = $this->db->get(); + + return $query->result(); + } + + // This Method to get the Service PO Details for Edit the Item + + function GetServicePurchaseOrder($PONO = '') + { + $this->db->distinct(); + $this->db->select('ReqNo,POMast.PONO,POMast.PaymentTerms,POMast.PaymentOtherDescription,ServiceDescription,supp.SupplierID,supp.SupplierName,supp.Address,PODate,Stat.StatusName,DeliveryOption,DeliverySchedule,DeliveryDate,DeliveryAddress,POMast.PaymentTerms,POMast.ExchangeRate,POMast.UpdatedOn,Stat.StatusCode,POMast.ServiceWorkStatus,POMast.*,POMast.TotalOrderValue,POMast.BudgetType,IGR.IGRNO'); + $this->db->from('T_PurchaseOrder_Master POMast'); + $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID'); + $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status'); + $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO'); + $this->db->join('T_IGR_Master IGR','POMast.PONO = IGR.PONO','left'); + + $this->db->where('POMast.PONO', $PONO); + $query = $this->db->get(); + + $result = $query->result(); + + return $result; + } + + // This Method to get the Service PO Child Details for Edit the Item + + +// This Method to get the Service PO Child Details for Edit the Item + function GetServicePurchaseOrderDetails($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.Per,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,LineItem.Quantity,ReceivedQuantity,Rate,LineItem.Status,(LineItem.Quantity *Rate) as BasicValue ,(After_CGST + After_SGST + After_IGST) as Taxamount,Dept.DepartmentName + ,TotalValue,CGST,After_CGST,SGST,After_SGST,IGST,After_IGST,otherallowance,LineItem.CostCenterCode,LineItem.ServiceFrequency,LineItem.ServiceMaterialDescription,Req.Schedule_Type,Req.NumberOfService,Req.Service_Period,ReqDet.MaterialDescription + FROM T_PurchaseOrder_LineItem LineItem + join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo + join T_Requestion_Details ReqDet on ReqDet.ReqNo = LineItem.ReqNo and LineItem.MaterialCode = ReqDet.MaterialCode + left join T_Employee_Details emp on Req.Requestedby = emp.EmpID + join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode + where LineItem.PONO =?'; + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + // This Method to get the Service PO Child Details for Edit the Item + function GetServicePurchaseOrderDetailsforPdf($PONO = '') + { + + + + $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.Per,LineItem.ServiceMaterialDescription,Mat.MaterialCode,Mat.MaterialName,POMaster.ParentPO, + Mat.UOM,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue,POMaster.AmendedDetails,LineItem.AmendedDetails as lineamenddetails, + ROUND(( Tax.After_SGST + Tax.After_CGST + Tax.After_IGST ) ,2)as Taxamount,ReqMat.NumberOfService,ReqMat.Schedule_Type,ReqMat.Service_Period, + TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,Payment.PaymentTerms,AdvanceAmount + FROM T_PurchaseOrder_LineItem LineItem + join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO + join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID + join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms + join T_Requestion_Master ReqMat on ReqMat.ReqNo = LineItem.ReqNo + left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO + where LineItem.PONO =?'; + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + + + + // This Method to get the Revenue PO Child Details for Edit the Item + function GetRevenuePurchaseOrderDetails($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity,Per,ServiceMaterialDescription,ReceivedQuantity,Rate,Req.Status,(Quantity *Rate) as BasicValue , (( AfterSGST + AfterCGST + + AfterIGST )) as Taxamount ,TotalValue,Tax.*,Req.CostCenterCode,Dept.DepartmentName + FROM T_PurchaseOrder_LineItem LineItem + join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + left join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo + left join T_Employee_Details emp on Req.Requestedby = emp.EmpID + join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode + where LineItem.PONO =?'; + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + + // This Method to get the Revenue PO Child Details for Edit the Item + function GetRevenuePurchaseOrderDetailsForPDF($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,ReqNo,Mat.MaterialCode,Mat.MaterialName,POMaster.PaymentOtherDescription,LineItem.ServiceMaterialDescription, + Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue , + ROUND(((AfterSGST + AfterCGST + + AfterIGST)) ,2)as Taxamount,AdvanceAmount, + TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.Address,sup.SupplierID,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,LineItem.AmendedDetails as LineAmend,Payment.PaymentTerms + FROM T_PurchaseOrder_LineItem LineItem + left join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + left join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO + join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID + left join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms + left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO + where LineItem.PONO =?'; + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + + function getRevenueTaxinforforpdf($PONO) + { + $subQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,rt.CGST,rt.SGST,rt.IGST,rt.FreightValue,rt.AfterFreightValue,rt.PackagingValue,rt.AfterPackagingValue,rt.DiscountValue,rt.AfterDiscount FROM T_Revenue_Tax rt + + join T_PurchaseOrder_LineItem pl on pl.LineItemNo=rt.LineItemNo + + join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO + + where pm.POType=? and pm.PONO=? + + group by rt.CGST,rt.SGST,rt.IGST,rt.FreightValue,rt.PackagingValue,rt.AfterDiscount,rt.AfterFreightValue,rt.AfterPackagingValue ORDER BY rt.LineItemNo ASC'; + + $query = $this->db->query($subQuery,array("REVENUE",$PONO)); + + return $query->result(); + + } +// This Method to get the Revenue PO Child Details for Edit the Item + + +function GetImportPurchaseOrderDetailsForPDF($PONO = '') + { + + // $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName, + // Mat.UOM,Quantity,ReqMas.Requestedby,Rate,ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount, + // ProductPrice,Tax.*,LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.Address + // FROM T_PurchaseOrder_LineItem LineItem + // join T_Requestion_Master ReqMas on ReqMas.ReqNo=LineItem.ReqNo + // join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + // join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + // join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO + // join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID + // where LineItem.PONO =?'; + + $subQuery='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName,Import_DispatchDetails,LineItem.Per,LineItem.ServiceMaterialDescription, +Mat.UOM,Quantity,ReqMas.Requestedby,Rate,ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount , +ProductPrice,Tax.*,LineItem.CostCenterCode ,Date(ReqMast.ReqDate) as ReqDate,POMaster.*,sup.SupplierName,sup.Address,LineItem.AmendedDetails as LineAmend,AdvanceAmount, Pay.PaymentTerms as Pay,ROUND((Quantity *Rate),2 ) as BasicValue,HSNCODE,sup.EmailAddress,sup.SupplierID,sup.PAN,sup.ContactNumber,sup.GSTNO +FROM T_PurchaseOrder_LineItem LineItem +join T_Requestion_Master ReqMas on ReqMas.ReqNo=LineItem.ReqNo +join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode +join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo +join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO +join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID +left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO +join T_Requestion_Master ReqMast on LineItem.ReqNo=ReqMast.ReqNo +join T_PaymentTerms Pay on POMaster.PaymentTerms=Pay.PaymentID +where LineItem.PONO =?'; + + $query = $this->db->query($subQuery,array($PONO)); + //print_r($this->db->last_query()); + + return $query->result(); + + + } + + + function GetCurrencyDetail($Currency='') + { + + $subQuery='SELECT * from T_Currency_Details where Currency_Code=?'; + $query=$this->db->query($subQuery,array($Currency)); + //print_r($query); + return $query->result(); + + } + + + function GerRequesterName($Requester='') + { + $subQuery='SELECT EmpID,FirstName,Departmentcode from T_Employee_Details where EmpID=?'; + + $query=$this->db->query($subQuery,array($Requester)); + + return $query->result(); + } + + + function GerRequesterDep($Depcode='') + { + $subQuery='SELECT DepartmentName from T_DepartmentDetails where DEPCode=?'; + $query=$this->db->query($subQuery,array($Depcode)); + + return $query->result(); + + } + + function GerCurrencyCodeName($Currencycode='') + { + $subQuery='SELECT * from T_Currency_Details where Currency_Code=?'; + $query=$this->db->query($subQuery,array($Currencycode)); + //print_r($this->db->last_query()); + return $query->result(); + + } + + + function GetPOStatus($Status='') + { + $subQuery='SELECT StatusName from T_Status where StatusCode=?'; + $query=$this->db->query($subQuery,array($Status)); + return $query->result(); + + } + + + function GetPaymentTerms($PONO='') + { + $subQuery='SELECT PaymentTerms from T_PurchaseOrder_Master where PONO=?'; + $query=$this->db->query($subQuery,array($PONO)); + //print_r($query); + return $query->result(); + + } + + + + + // function getSupplierPayment($Currency='') + // { + + // $subQuery='select distinct PaymentTerms from T_SupplierDetailsN'; + // $query=$this->db->query($subQuery,array($Currency)); + // //print_r($this->db->last_query()); + // return $query->result(); + + // } + + function getSupplierPayment($Config_ID='') + { + + // $subQuery='select distinct PaymentTerms from T_SupplierDetailsN'; + $subQuery='select ConfigValue from T_ConfigDetails where Config_ID=?'; + $query=$this->db->query($subQuery,array($Config_ID)); + //print_r($this->db->last_query()); + return $query->result(); + + } + + function GetWorkStatus($Config_ID='') + { + $subQuery = 'select ConfigValue from T_ConfigDetails where Config_ID=?'; + $query=$this->db->query($subQuery,array($Config_ID)); + //print_r($query); + return $query->result(); + } + + + + + +function GetImportPurchaseOrderDetails($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName, +Mat.UOM,Quantity,Rate,Req.Status,ROUND((Quantity *Rate),2 ) as BasicValue,ReceivedQuantity, +QuantityRejected,ROUND(Quantity-ReceivedQuantity)as PendingQty,Per, + ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,LandingCharge,HighSeasSalesCharge,CustomDuty,ExciseDuty,ExciseDutyEdCess,CustomEdCess,POMast.ExchangeRate,AfterLandingCharge,AfterHighSeasSalesCharge,AfterCustomDuty,AfterExciseDuty,AfterExciseDutyEdCess,AddlExciseDuty,AfterAddlExciseDuty,Grossdutypayable,AvailableModvat,Grossexpensesduetocustomduty,purchaseratePerKG,CustomDutyExpensesPerKG,RMCIncludingCustomersPerKG,QuantityKG,BasicPriceInMTon,ProductPrice,CustomSHCess,AfterCustomSHCess,AfterExciseDutySHCess,ExciseDutySHCess, + AfterCustomEdCess,ROUND((Quantity *Rate),2)as TotalOrderValue,ROUND((POMast.ExchangeRate*BasicPriceInMTon),2) as BasicINRValue,TotalValue,CurrencyType,ReceivedQuantity,Tax.*,LineItem.ServiceMaterialDescription, + + Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem + join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO + join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo + left join T_Employee_Details emp on Req.Requestedby = emp.EmpID + + left join T_MRIR_Master Mast on POMast.PONO=Mast.PONO + + left join T_MRIR_Details Det on Det.MaterialCode=LineItem.MaterialCode and Mast.MRIRNO=Det.MRIRNO + + join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode where LineItem.PONO =?'; + //print_r($subQuery); + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + + + + + +function GetCurrencytype() + { + + $subQuery = 'select * from T_Currency_Details'; + + $query = $this->db->query($subQuery); + + return $query->result(); + } + + function GetINRCurrencytype($Currency_Code='') + { + $subQuery='select * from T_Currency_Details where Currency_Code=?'; + $query=$this->db->query($subQuery,array($Currency_Code)); + //print_r($this->db->last_query()); + return $query->result(); + + } + + + + + + + // To Update the PO + function updatePOMaster($PONO,$PODetails) + { + $this->db->where('PONO', $PONO); + $this->db->update('T_PurchaseOrder_Master', $PODetails); + + return TRUE; + } + + + // To update Parent PO as Amended PO + function updateAmendPOMaster($PONO,$PODetail) + { + //echo $PONO."from model"; + + + $this->db->where('PONO', $PONO); + $this->db->update('T_PurchaseOrder_Master', $PODetail); + $insert_id = $this->db->affected_rows(); + + return $insert_id; + } + /** + * This function is used to check the Line Item is already available in the database + * @return array $result : This is result of the query + */ + function LineItemExists($LineItemNo) + { + $this->db->select('LineItemNo,TaxID'); + $this->db->from('T_Service_Tax'); + $this->db->where('LineItemNo ',$LineItemNo ); + //$this->db->where('Requestedby ',$ReqBy ); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + //echo $result->num_rows; + return $query->result_array(); + } + } + /** + * This function is used to check the Revenue Line Item is already available in the database + * @return array $result : This is result of the query + */ + function LineItemExistsinRevenueTax($LineItemNo) + { + $this->db->select('LineItemNo'); + $this->db->from('T_Revenue_Tax'); + $this->db->where('LineItemNo ',$LineItemNo ); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + return $query->result_array(); + } + } + + + function LineItemExistsinImportTax($LineItemNo) + { + $this->db->select('LineItemNo'); + $this->db->from('T_Import_Tax'); + $this->db->where('LineItemNo ',$LineItemNo ); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + return $query->result_array(); + } + } + // To Update the PO Line Item + function updatePOLineItem($PONO,$LineItemNo,$PODetails) + { + $this->db->where('PONO', $PONO); + $this->db->where('LineItemNo', $LineItemNo); + $this->db->update('T_PurchaseOrder_LineItem', $PODetails); + + return TRUE; + } + /*// To Update the Service Tax Item */ + function updateServiceTax($LineItemNo,$PODetails) + { + + $this->db->where('LineItemNo', $LineItemNo); + $this->db->update('T_Service_Tax', $PODetails); + + // print_r($this->db->last_query()); + + return TRUE; + } + + /*// To Update the Revenue Tax Item */ + function updateRevenueTax($LineItemNo,$PODetails) + { + $this->db->where('LineItemNo', $LineItemNo); + $this->db->update('T_Revenue_Tax', $PODetails); + + // print_r($this->db->last_query()); + + return TRUE; + } + + function updateImportTax($LineItemNo,$PODetails) + { + $this->db->where('LineItemNo', $LineItemNo); + $this->db->update('T_Import_Tax', $PODetails); + + // print_r($this->db->last_query()); + + return TRUE; + } + + function getLastInsertedPO() + { + $this->db->select('max(PONO) as PO'); + $this->db->from('T_PurchaseOrderDetails'); + $query = $this->db->get(); + + return $query->result_array(); + } + + + /* This Method to get all the Department name for the requistion */ + function getDepartmentListForAllReq() + { + $subQuery ='SELECT DISTINCT DEPT.DEPCode,DEPT.DepartmentName FROM T_Requestion_Master REQ + JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID + JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode WHERE REQ.Status not in(?,?,?,?)'; + + $query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED)); + //print_r($query); + return $query->result(); + } + /* + This Method to get all department list + */ + function getDepartmentAllList() + { + $subQuery ='SELECT DISTINCT DEPCode,DepartmentName FROM T_DepartmentDetails'; + + $query = $this->db->query($subQuery); + //print_r($query); + return $query->result(); + } + + + function getStatusListforAllReq() + { + $subQuery ='SELECT DISTINCT STAT.StatusCode, STAT.StatusName FROM T_Requestion_Master REQ + JOIN T_Status STAT on REQ.Status = STAT.StatusCode where STAT.StatusCode not in (?,?,?,?)'; + $query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED)); + + // print_r( $this->db->last_query()); + + return $query->result(); + } + + function getStatusByDepartment($DepNo='') + { + + $subQuery ='SELECT DISTINCT STAT.StatusCode ,STAT.StatusName FROM T_Requestion_Master REQ + JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID + JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode + JOIN T_Status STAT ON REQ.Status = STAT.StatusCode + WHERE DEPT.DEPCode=? AND REQ.Status NOT IN (?,?,?,?)'; + $query = $this->db->query($subQuery,array($DepNo,REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED)); + + return $query->result_array(); + } + + function getRequistionListbySearch($Depid='',$Status='',$FromDate='',$ToDate='') + { + $subQuery =' SELECT ReqNo,ReqType,Requestedby,EMP.FirstName,EMP.Designation,STAT.StatusCode ,STAT.StatusName,ReqDate,DEPT.DEPCode,DEPT.DepartmentName FROM T_Requestion_Master REQ + JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID + JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode + JOIN T_Status STAT on REQ.Status = STAT.StatusCode + where REQ.Status NOT IN (?,?,?,?,?)'; + + $appendQuery = $subQuery ; + + if($Depid != '' && $Status != '' && $FromDate != '' && $ToDate != '') + { + $appendQuery .= ' AND DEPT.DEPCode=? AND STAT.StatusCode=? AND ReqDate >= ? AND ReqDate <= ?'; + //echo "$appendQuery";die(); + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$Status,$FromDate,$ToDate)); + //print_r($this->db->last_query()); + return $query->result_array(); + } + else if($Depid != '' && $Status == '' && $FromDate == '' && $ToDate == '') + { + $appendQuery .= ' AND DEPT.DEPCode=?'; + + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid)); + //print_r($this->db->last_query()); + return $query->result_array(); + } + else if($Depid == '' && $Status != '' && $FromDate == '' && $ToDate == '') + { + $appendQuery .= ' AND STAT.StatusCode=?'; + + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Status)); + //print_r($this->db->last_query()); + return $query->result_array(); + } + else if($Depid == '' && $Status == '' && $FromDate != '' && $ToDate != '') + { + $appendQuery .= ' AND ReqDate >= ? AND ReqDate <= ?'; + + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$FromDate,$ToDate)); + //print_r($this->db->last_query()); + return $query->result_array(); + } + else if($Depid != '' && $Status != '' && $FromDate == '' && $ToDate == '') + { + $appendQuery .= ' AND DEPT.DEPCode=? AND STAT.StatusCode=?'; + + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$Status)); + // print_r($this->db->last_query()); + return $query->result_array(); + } + else if($Depid != '' && $Status == '' && $FromDate != '' && $ToDate != '') + { + $appendQuery .= ' AND DEPT.DEPCode=? AND ReqDate >= ? AND ReqDate <= ?'; + + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$FromDate,$ToDate)); + //print_r($this->db->last_query()); + return $query->result_array(); + } + else if($Depid == '' && $Status != '' && $FromDate != '' && $ToDate != '') + { + $appendQuery .= ' AND STAT.StatusCode=? AND ReqDate >= ? AND ReqDate <= ?'; + + $query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Status ,$FromDate,$ToDate)); + // print_r($this->db->last_query()); + return $query->result_array(); + } + else + { + $query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED)); + //print_r($this->db->last_query()); + return $query->result(); + } + + } + + function UpdateRequistItemStatus() + { + $query = $this->db->query("update T_Requestion_Details REQ + JOIN T_PurchaseOrder_LineItem line ON REQ.ReqNo = line.ReqNo + JOIN T_PurchaseOrder_Master PO ON PO.PONO = line.PONO + set REQ.Status = CASE WHEN REQ.Quantity = line.Quantity THEN 'ST022' WHEN REQ.Quantity > line.Quantity THEN 'ST023' ELSE 'ST003' END , + REQ.updatedOn= CURRENT_TIMESTAMP + where PO.Status ='".PO_CREATED."'"); + + //$query ->next_result(); + + } + function UpdateRequistionStatus() + { + $result = $this->db-> query("CALL P_UPDATE_REQUISTIONSTATUS_New()") or die(mysql_error()); + + $result ->next_result(); + + } + /** + * This function is used to delete the Line item from details into Database + * @return array $result : This is result of the query + */ + function DeletePOLineItem( $LineItem='',$ReqNo='',$MaterialCode='') + { + $this->db->where('LineItemNo', $LineItem); + $this->db->where('ReqNo', $ReqNo); + $this->db->where('MaterialCode', $MaterialCode); + $this->db->delete('T_PurchaseOrder_LineItem'); + + return TRUE; + } + + /** + * This function is used to delete the Revenue item from details into Database + * @return array $result : This is result of the query + */ + function DeletePORevenueTax( $LineItem='') + { + $this->db->where('LineItemNo', $LineItem); + $this->db->delete('T_Revenue_Tax'); + + return TRUE; + } + + /** + * This function is used to delete Service Tax from details into Database + * @return array $result : This is result of the query + */ + function DeletePOServiceTax( $LineItem='') + { + $this->db->where('LineItemNo', $LineItem); + $this->db->delete('T_Service_Tax'); + + return TRUE; + } + + + function DeletePOImportTax( $LineItem='') + { + $this->db->where('LineItemNo', $LineItem); + $this->db->delete('T_Import_Tax'); + + return TRUE; + } + + /** + * This function is used to get the List of PO details to the approver + * @return array $result : This is result of the query + join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode + */ + function getPOList($type) + { + + $this->db->distinct(); + $this->db->select('mast.PONO,mast.TotalOrderValue,st.StatusCode,st.StatusName,emp.FirstName,mast.CreatedDate,ccm.CostCenterName,ccm.CostCenterCode,mast.POType as RType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,rmast.ReqType,mast.Status,mast.CapitalRange, +(select FirstName from T_Employee_Details where EmpID=EID)as Approver'); + $this->db->from('T_PurchaseOrder_Master mast'); + // $this->db->order_by('mast.Status',"PO_CREATED"); + $this->db->join('T_Status st', 'st.StatusCode=mast.Status'); + + $this->db->join('T_PurchaseOrder_LineItem req', 'req.PONO= mast.PONO'); + $this->db->join('T_Requestion_Master rmast','rmast.ReqNo=req.ReqNo'); + //$this->db->join('T_CostCenter_Budget bud','bud.CostCenterCode = req.CostCenterCode and bud.BudgetType = rmast.ReqType'); + $this->db->join('T_CostCenter_Master ccm','ccm.CostCenterCode = req.CostCenterCode','left'); + $this->db->join('tbl_users tbl', 'rmast.createdby=tbl.userid'); + $this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid'); + $this->db->join('T_DepartmentDetails as Dep','Dep.DEPCode=emp.Departmentcode'); + + if($type=='APPROVAL'){ + $this->db->or_where('mast.Status',PO_CREATED); + $this->db->or_where('mast.Status',PO_APPROVER_ONHOLD); + $this->db->or_where('mast.Status',PO_AWAITING_RELEASE); + $this->db->or_where('mast.Status',PO_RELEASED); + $this->db->or_where('mast.Status',REQITEM_Emergency_PO_CREATED); + $this->db->order_by('mast.Status'); + + } + else if($type=='RELEASE'){ + $this->db->or_where('mast.Status',PO_AWAITING_RELEASE); + $this->db->or_where('mast.Status',PO_RELEASER_ONHOLD); + $this->db->or_where('mast.Status',PO_RELEASED); + $this->db->order_by('mast.Status'); + + + + } + $result=$this->db->get(); + // print_r($this->db->last_query()); + return $result->result(); + + } + + + function UpdatePO($store, $PONO) + { + + $this->db->where('PONO', $PONO); + $this->db->update('T_PurchaseOrder_Master', $store); + + return TRUE; + } + + function GetReleasedDetails($PONO){ + $this->db->select('mast.ReleasedOn,re.FirstName'); + $this->db->from('T_PurchaseOrder_Master mast'); + $this->db->join('tbl_users tbl','mast.ReleasedBy=tbl.userid'); + $this->db->join('T_Employee_Details re','re.EmpID=tbl.EmpID'); + $this->db->where('mast.PONO',$PONO); + $result=$this->db->get(); + //print_r($this->db->last_query()); +//die(); + return $result->result(); + + } + //This is get the capital po list for edit + +function getCapitalPurchaseOrderDetails($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.ServiceMaterialDescription,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency, +Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,Tax.*, + ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,LandingCharge,HighSeasSalesCharge,CustomDuty,ExciseDuty,ExciseDutyEdCess,CustomEdCess,POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,AfterLandingCharge,AfterHighSeasSalesCharge,AfterCustomDuty,AfterExciseDuty,AfterExciseDutyEdCess,AddlExciseDuty,AfterAddlExciseDuty,Grossdutypayable,AvailableModvat,Grossexpensesduetocustomduty,purchaseratePerKG,CustomDutyExpensesPerKG,RMCIncludingCustomersPerKG,QuantityKG,BasicPriceInMTon,ProductPrice,CustomSHCess,AfterCustomSHCess,AfterExciseDutySHCess,ExciseDutySHCess,AfterCustomEdCess,ROUND((POMast.ExchangeRate*BasicPriceInMTon*Quantity),2) as BasicINRValue,Tax.TotalValue as ImportTotalValue,Tax.FreightType,Tax.NoOfTrip,Tax.FreightValue,Tax.AfterFreightValue,POMast.CurrencyType, + + Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem + join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO +join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + + join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo + join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo +left join T_Employee_Details emp on Req.Requestedby = emp.EmpID + + join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode where LineItem.PONO =?'; + //print_r($subQuery); + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + +// This Method to get the Capital PO Details for pdf + function GetCapitalPurchaseOrderDetailsForPDF($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.AmendedDetails as lineamd,ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription, + Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue , + LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,Payment.PaymentID,Payment.PaymentTerms,AdvanceAmount,HSNCODE + FROM T_PurchaseOrder_LineItem LineItem + join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + + join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO + join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID + join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms + left join T_PurchaseOrder_AdvanceRequest Adv on POMaster.PONO=Adv.PONO + where LineItem.PONO =?'; + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + // get requested by details + function GetRequesedByDetails($PONO){ + $this->db->select('mast.CreatedBy,re.FirstName,Dept.DEPCode,Dept.DepartmentName'); + $this->db->from('T_PurchaseOrder_Master mast'); + $this->db->join('tbl_users tbl','mast.CreatedBy=tbl.userid'); + $this->db->join('T_Employee_Details re','re.EmpID=tbl.EmpID'); + $this->db->join('T_DepartmentDetails Dept', 're.Departmentcode = Dept.DEPCode'); + + $this->db->where('mast.PONO',$PONO); + $result=$this->db->get(); + + return $result->result(); + + } + + // get domestic capital po list + + + function getDomesticCapitalPurchaseOrderDetails($PONO = '') + { + + $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.ServiceMaterialDescription,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency, + Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,ROUND((ServiceTax.After_CGST + ServiceTax.After_SGST + ServiceTax.After_IGST),2) as ServiceTaxamount + ,ServiceTax.TotalValue,ServiceTax.CGST,ServiceTax.After_CGST,ServiceTax.SGST,ServiceTax.After_SGST,ServiceTax.IGST,ServiceTax.After_IGST,ServiceTax.otherallowance,ServiceTax.discount,ServiceTax.discountval,ServiceTax.Afterdiscountval, + POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,ROUND((POMast.TotalOrderValue),2) as BasicINRValue,POMast.CurrencyType,FreightType as Ftype,NoOfTrip as NoTrip,FreightValue as Fvalue,AfterFreightValue as Afvalue, + + Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem + join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO + join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode + join T_Service_Tax ServiceTax on ServiceTax.LineItemNo = LineItem.LineItemNo + join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo + join T_Employee_Details emp on Req.Requestedby = emp.EmpID + + join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode where LineItem.PONO =?'; + //print_r($subQuery); + + $query = $this->db->query($subQuery,array($PONO)); + + return $query->result(); + + + } + //get pdf po requistion details + + + function GetPdfRequistionDetails($PONO){ + $this->db->select('LineItem.ReqNo'); + $this->db->from('T_PurchaseOrder_LineItem LineItem'); + $this->db->where('LineItem.PONO',$PONO); + $result=$this->db->get(); + $ReqNo=''; + + foreach ($result->result() as $res){ + + if($ReqNo==$res->ReqNo){ + + } + else{ + $ReqNo = $res->ReqNo; + $this->db->select('ReqMast.ReqNo,ReqMast.CostCenterCode,ReqMast.ReqDate,ReqMast.Schedule_Type,ReqMast.NumberOfService,ReqMast.Service_Period,Dept.DEPCode,Dept.DepartmentName,Dept.shortName'); + $this->db->from('T_Requestion_Master ReqMast'); + + $this->db->join('T_DepartmentDetails Dept', 'ReqMast.RequestedDept = Dept.DEPCode'); + $this->db->where('ReqMast.ReqNo',$ReqNo); + $Reqresult=$this->db->get(); + $Details['RequistionNo']= $Reqresult->result()[0]->ReqNo; + $Detaisl['ReqDate']=$Reqresult->result()[0]->ReqDate; + + $Details['RequestedDept']= $Reqresult->result()[0]->shortName; + $Details['CostCenterCode']= $Reqresult->result()[0]->CostCenterCode; + $date = new DateTime($Reqresult->result()[0]->ReqDate,new DateTimeZone('Asia/Kolkata')); + $retDate = $date->format('d-m-Y'); + $Details['ReqDate']= $retDate; + $ScheduleType = $Reqresult->result()[0]->Schedule_Type; + if($ScheduleType!='Recurring'){ + $Details['Frequency']= $Reqresult->result()[0]->Schedule_Type; + + } + else{ + $Details['Frequency']= $Reqresult->result()[0]->Service_Period.' - '.$Reqresult->result()[0]->NumberOfService; + } + + $ResultArray[]=$Details; + } + + } + + $RequistionDetails = $ResultArray; + return $RequistionDetails; + } + function GetLineItemReceivedQty($ParentPO,$MaterialCode) + { + $this->db->select('ReceivedQuantity'); + $this->db->from('T_PurchaseOrder_LineItem'); + + $this->db->where('PONO',$ParentPO); + $this->db->where('MaterialCode',$MaterialCode); + $result=$this->db->get(); + + return $result->result_array(); + } + + //get paymentTerms details + + function getPaymentTermsDetails($Payment_ID='') + { + + + $getpaymentQuery='select distinct PaymentID,PaymentTerms,Details from T_PaymentTerms'; + $paymentQuery=$this->db->query($getpaymentQuery); + + return $paymentQuery->result(); + + } + /** + * This function is used to get status in status table + + */ + function getStatus($StatusType = '') + { + $this->db->select('StatusCode,StatusName '); + $this->db->from('T_Status'); + $this->db->where('StatusType', $StatusType); + $query = $this->db->get(); + + return $query->result(); + } + + + function edit_mrir($MrirNo) + { + $this->db->distinct(); + $this->db->select('TMM.MRIRNO,TMM.PONO,TMM.IGRNO,TMM.Createdon,TMD.ActualQuantityReceived,IGRM.DeliveryChellanOrInvoiceNo,IGRM.DeliveryChellanDate,IGRM.VehicleNo,IGRM.CourierNo,IGRM.CreatedDate,IGRD.QuantityAsPerInvoice,SUPP.SupplierName,SUPP.Address,POMR.PODate,POMR.DeliveryDate,POMR.ServiceDescription,TMD.MaterialCode,MM.MaterialName,MM.UOM,POLT.Quantity,POLT.ReceivedQuantity,ED.FirstName as PORasiedbyName,ED1.FirstName as MRIRRasiedbyName, ED2.FirstName as IGRRasiedbyName,TMM.MRIRStatus,TMM.Createdon as MRIRCreatedon,POLT.CostCenterCode,CostCenterName,QuantityAccepted,QuantityRejected,TMD.Remarks'); + $this->db->from ('T_MRIR_Master TMM'); + $this->db->join ('T_MRIR_Details TMD','TMM.MRIRNO = TMD.MRIRNO','left');//to get IGRNO,PONO,MRIRNO,mrirdate, + $this->db->join ('T_IGR_Master IGRM', 'IGRM.IGRNO = TMM.IGRNO','left');//to get actualquantity,deliverydate,Invoicedate,vechileno,courierno,igrdate, + $this->db->join ('T_PurchaseOrder_Master POMR ','IGRM.PONO = POMR.PONO','left');//to get podate,deliverydate,servicedescription + $this->db->join ('T_PurchaseOrder_LineItem POLT','IGRM.PONO=POLT.PONO','left');//to get receivedquantity,quantity + + $this->db->join ('T_IGR_Details IGRD','IGRD.IGRNO = IGRM.IGRNO','left');//to get invoicequantity + $this->db->join ('T_MaterialMaster MM','IGRD.MaterialCode = MM.MaterialCode','left'); + $this->db->join ('T_SupplierDetailsN SUPP','POMR.SupplierID = SUPP.SupplierID','left');//to get suppliername,supplieraddress + $this->db->join ('tbl_users user','user.userid = POMR.CreatedBy','left');//to get poraisedby + $this->db->join ('T_Employee_Details ED','ED.EmpID = user.EmpID','left'); + $this->db->join ('tbl_users user1','user1.userid=TMM.CreatedBy','left');//to get mrirraisedby + $this->db->join ('T_Employee_Details ED1','ED1.EmpID = user1.EmpID','left'); + $this->db->join ('tbl_users user2','user2.userid=IGRM.CreatedBy','left');//to get igrraisedby + $this->db->join ('T_Employee_Details ED2','ED2.EmpID = user2.EmpID','left'); + $this->db->join('T_CostCenter_Master TCOST','POLT.CostCenterCode=TCOST.CostCenterCode'); + $this->db->where('TMM.MRIRNO',$MrirNo); + $this->db->group_by('TMM.MRIRNO,TMD.MaterialCode'); + $query = $this->db->get(); + $result = $query->result(); + //print_r( $this->db->last_query()); + return $result; + + } + + + + + + function getadvancePONO($Status='') + { + $this->db->select ('Mast.PONO,POType,Mast.CreatedDate,Mast.ReleasedOn,Mast.TotalOrderValue,Mast.SupplierID,DeliveryDate,DeliverySchedule,DeliveryOption,Mast.PaymentTerms as Paycode,Payterm.PaymentTerms,LineItem.ReqNo,Requestedby,Departmentcode,DepartmentName,LineItem.CostCenterCode,SupDet.SupplierName,Import_DispatchDetails,CurrencyType,AdvancePercentage,AdvanceAmount,POAdv.Remarks,Mast.CapitalRange,Mast.PaymentOtherDescription,RequestedDept'); + $this->db->from('T_PurchaseOrder_Master Mast'); + $this->db->join('T_PurchaseOrder_LineItem LineItem','Mast.PONO=LineItem.PONO'); + $this->db->join('T_Requestion_Master ReqMa','LineItem.ReqNo=ReqMa.ReqNo'); + $this->db->join('T_Employee_Details EmpDet','ReqMa.Requestedby=EmpDet.EmpID','left'); + $this->db->join('T_DepartmentDetails DepDet','EmpDet.Departmentcode=DepDet.DEPCode or ReqMa.RequestedDept=DepDet.DEPCode','left'); + $this->db->join('T_SupplierDetailsN SupDet','Mast.SupplierID=SupDet.SupplierID'); + $this->db->join('T_PurchaseOrder_AdvanceRequest POAdv','Mast.PONO=POAdv.PONO','left'); + $this->db->join('T_PaymentTerms Payterm','Mast.PaymentTerms=Payterm.PaymentID'); + $this->db->where('Mast.Status',$Status); + $query = $this->db->get(); + // print_r($this->db->last_query()); + return $query->result(); + + } + + // update req deatail if work status is completed + + function updateReqDetail($PONO,$POStatus,$MaterialCode) + { + + $this->db->set('Req.Status',$POStatus); + $this->db->where('Item.PONO',$PONO); + $this->db->where('Req.MaterialCode',$MaterialCode); + $this->db->update('T_PurchaseOrder_LineItem Item JOIN T_Requestion_Details Req ON Item.ReqNo= Req.ReqNo'); + return TRUE; + } + + function UpdateReceivedQtyforServicePO($PONO,$updateddt,$updatedBy) + { + $this->db->select('LineItemNo,MaterialCode'); + $this->db->from('T_PurchaseOrder_LineItem'); + $this->db->where('PONO ',$PONO ); + $query = $this->db->get(); + $result = $query->result(); + + if(!empty($result)) + { + foreach ($result as $res) + { + $LineItemNo =$res->LineItemNo; + $MaterialCode = $res->MaterialCode; + //echo $LineItemNo; + + $subQuery = 'update T_PurchaseOrder_LineItem + set ReceivedQuantity=Quantity, status=?,UpdatedOn=?,UpdateBY=? where PONO=? and LineItemNo=?'; + + $query = $this->db->query($subQuery,array(PO_SERVICE_COMPLETED,$updateddt,$updatedBy,$PONO,$LineItemNo)); + $finddot = strpos($PONO,'.'); + if($finddot = true) + { + $subQuery = 'update T_PurchaseOrder_LineItem + set ReceivedQuantity=Quantity, status=?,UpdatedOn=?,UpdateBY=? where PONO=substring(?,1,(case when INstr(?,?) > 0 then INstr(?,?)-1 else 0 end)) and MaterialCode=?'; + + $query = $this->db->query($subQuery,array(PO_SERVICE_COMPLETED,$updateddt,$updatedBy,$PONO,$PONO,'.',$PONO,'.',$MaterialCode)); + } + + } + + } + + } +//get service tax listusing po number + function GetServiceTaxDetails($PONO = ''){ + + $taxQuery ='SELECT group_concat(@count:=@count+1) Itemcode, +st.CGST,st.SGST,st.IGST,st.otherallowance FROM T_Service_Tax st + join T_PurchaseOrder_LineItem pl on pl.LineItemNo=st.LineItemNo + join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO JOIN + (SELECT @count := 0) count + where pm.POType=? and pm.PONO=? + group by st.CGST,st.SGST,st.IGST,st.otherallowance + ORDER BY Itemcode ASC '; + + + $query = $this->db->query($taxQuery,array("SERVICE",$PONO)); + + return $query->result(); + } + // get capital tax listing by po no + + function GetCapitalTaxListDetails($PONO = '',$CapitalRange=''){ + + if($CapitalRange==1){ + $taxQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,SUM(st.`After_CGST`) AS TotalCGST,SUM(st.`After_SGST`) AS TotalSGST,SUM(st.`After_IGST`) AS TotalIGST,SUM(st.`otherallowance`) AS TotalOtherAllowance,SUM(st.`Afterdiscountval`) AS TotalDiscount,st.discountval,st.Afterdiscountval,st.CGST,st.SGST,st.IGST,st.otherallowance,SUM(st.`AfterFreightValue`) AS TotalFreight,st.FreightValue FROM T_Service_Tax st + join T_PurchaseOrder_LineItem pl on pl.LineItemNo=st.LineItemNo + join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO + where pm.POType=? and pm.PONO=? + group by st.Afterdiscountval,st.CGST,st.SGST,st.IGST,st.otherallowance ORDER BY st.LineItemNo ASC'; + $query = $this->db->query($taxQuery,array("CAPITAL",$PONO)); + + return $query->result(); + } + else if($CapitalRange==0){ + $taxQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode, + SUM(it.`AfterFreightValue`) AS TotalFreight,it.FreightValue,it.AfterFreightValue, + it.IGST AS TotalIGSTPer,SUM(it.AfterIGST) as AfterIGST1,it.AfterIGST as AIgst FROM T_Import_Tax it + join T_PurchaseOrder_LineItem pl on pl.LineItemNo=it.LineItemNo + join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO + where pm.POType=? and pm.PONO=? + group by it.AfterFreightValue ORDER BY it.LineItemNo ASC'; + $query = $this->db->query($taxQuery,array("CAPITAL",$PONO)); + + return $query->result(); + } + + } + // get po format for acedamic year based + function GetPoFormat($PONO=''){ + $poQuery ='select PONO from T_PurchaseOrder_Master where PONO=?'; + $query = $this->db->query($poQuery,array($PONO)); + + return $query->result(); +} +//get Dept Emp Name +function getDepartmentEmpList($DepCode=''){ + $this->db->select('EmpID'); + $this->db->from('T_Employee_Details'); + $this->db->where('Departmentcode', $DepCode); + $this->db->limit('1'); + $query = $this->db->get(); + + return $query->result(); +} +//get req master details using reqno +function GetRequistionMasterUsingReqNo($Req){ + + + $this->db->select('Requestedby'); + $this->db->from('T_Requestion_Master'); + $this->db->where('ReqNo', $Req[0]); + $query = $this->db->get(); + + return $query->result(); + + +} +function amendpdf($PONO='') +{ + $Amend ='select p.PONO,p.ParentPO,p.Status,p.TotalOrderValue, + m.Status as parentpostatus, + m.TotalOrderValue as partenttotalorder + from T_PurchaseOrder_Master as p + join T_PurchaseOrder_Master as m + on m.PONO = p.ParentPO + where p.PONO = ?'; + $amendment = $this->db->query($Amend,array($PONO)); + + return $amendment->result(); +} + + + + function GetClients() + { + $this->db->select('client_id,client_name'); + $this->db->from('ip_clients'); + $query = $this->db->get(); + return $query->result_array(); + } + + + function SaveEnquiry($save) + { + $this->db->trans_start(); + $this->db->insert('T_Enquiry', $save); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; + + } + + + function UpdateEnquiry($save,$Id) + { + + $this->db->where('Id',$Id); + $this->db->update('T_Enquiry',$save); + $insert_id = $this->db->affected_rows(); + return $insert_id; + } + + + function GetEnquiryDetails() + { + $this->db->select('T_Enquiry.*,client_name'); + $this->db->from('T_Enquiry'); + $this->db->join('ip_clients','ip_clients.client_id=T_Enquiry.client_id'); + $this->db->order_by('Id','desc'); + $query = $this->db->get(); + return $query->result(); + + } + + + function GetEnquiry($Id) + { + $this->db->select('T_Enquiry.*,client_name'); + $this->db->from('T_Enquiry'); + $this->db->join('ip_clients','ip_clients.client_id=T_Enquiry.client_id'); + $this->db->where('Id',$Id); + $this->db->order_by('Id','desc'); + $query = $this->db->get(); + return $query->result(); + } + + + +function GetEnquiryCount($createddt) +{ + + $this->db->select('count(Id) as Countnumber'); + $this->db->from('T_Enquiry'); + $this->db->where('Created_Date',$createddt); + $query = $this->db->get(); + return $query->result(); +} + + +function SaveActionMaster($master) +{ + + $this->db->trans_start(); + $this->db->insert('T_ActionReport_Master', $master); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + // print_r($this->db->last_query()); + if($insert_id>0) + { + $subQuery = 'select max(Id) as Id from T_ActionReport_Master'; + + $query = $this->db->query($subQuery,array()); + + return $query->result_array(); + } +} + + +function SaveActionDisposition($actionsave) +{ + $this->db->trans_start(); + $this->db->insert('T_Action_Disposition',$actionsave); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; +} + + +function UpdateActionDisposition($actionsave,$LineDisposition) +{ + //echo $LineDisposition; + + $this->db->where('DispositionId', $LineDisposition); + $this->db->update('T_Action_Disposition', $actionsave); + return TRUE; +} + +function UpdateRootCause($rootsave,$Lineroot) +{ + $this->db->where('RootId', $Lineroot); + $this->db->update('T_RootCause', $rootsave); + return TRUE; +} + + +function Updatecounteraction($savecounter,$LineCounter) +{ + $this->db->where('CounterId', $LineCounter); + $this->db->update('T_Action_Counter_Measure', $savecounter); + return TRUE; +} + + +function UpdateActionMaster($master,$Id) +{ + + $this->db->where('Id', $Id); + $this->db->update('T_ActionReport_Master', $master); + $insert_id = $this->db->affected_rows(); + //return TRUE; + if($insert_id>0) + { + $subQuery = 'select max(Id) as Id from T_ActionReport_Master'; + + $query = $this->db->query($subQuery,array()); + + return $query->result_array(); + } +} + + + +function SaveRootCause($rootsave) +{ + + $this->db->trans_start(); + $this->db->insert('T_RootCause',$rootsave); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; + +} + +function Savecounteraction($savecounter) +{ + $this->db->trans_start(); + $this->db->insert('T_Action_Counter_Measure',$savecounter); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; +} + +function GetNcrlist() +{ + $this->db->select('*'); + $this->db->from('T_ComplaintRegister'); + $this->db->join('ip_clients','ip_clients.client_id=T_ComplaintRegister.client_id'); + $this->db->order_by('CId','desc'); + $query = $this->db->get(); + return $query->result(); +} + + +function GetncrmasterDetails($Id) +{ + $this->db->select('*'); + $this->db->from('T_ActionReport_Master'); + $this->db->where('Id',$Id); + $query = $this->db->get(); + return $query->result(); +} + + +function GetDispositionDetails($Id) +{ + $this->db->select('*'); + $this->db->from('T_Action_Disposition'); + $this->db->where('Id',$Id); + $query = $this->db->get(); + return $query->result(); + +} + +function GetRootcauseDetails($Id) +{ + $this->db->select('*'); + $this->db->from('T_RootCause'); + $this->db->where('Id',$Id); + $query = $this->db->get(); + return $query->result(); + +} + +function GetCouteractionDetails($Id) +{ + + $this->db->select('*'); + $this->db->from('T_Action_Counter_Measure'); + $this->db->where('Id',$Id); + $query = $this->db->get(); + return $query->result(); +} + + + +function Savecomplaint($save_complaint) +{ + $this->db->trans_start(); + $this->db->insert('T_ComplaintRegister',$save_complaint); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; +} + + +function Get_SavedComplaint($CId) +{ + $this->db->select('*'); + $this->db->from('T_ComplaintRegister'); + $this->db->join('ip_clients','ip_clients.client_id=T_ComplaintRegister.client_id'); + $this->db->where('CId',$CId); + $this->db->order_by('CId','desc'); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); +} + +function Updatecomplaint($save_complaint,$CId) +{ + + $this->db->where('CId', $CId); + $this->db->update('T_ComplaintRegister', $save_complaint); + return TRUE; +} + +function updatecomplaintId($up,$CId) +{ + $this->db->where('CId', $CId); + $this->db->update('T_ComplaintRegister',$up); + return TRUE; +} + + +function GetActionid($LineDisposition) +{ + + $this->db->select('*'); + $this->db->from('T_Action_Disposition'); + $this->db->where('DispositionId',$LineDisposition); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); +} + + + +function GetlastDispositionId() +{ + $subQuery = 'select max(DispositionId) from T_Action_Disposition'; + + $query = $this->db->query($subQuery,array()); + + return $query->result_array(); +} + + + +function Getrootid($Lineroot) +{ + $this->db->select('*'); + $this->db->from('T_RootCause'); + $this->db->where('RootId',$Lineroot); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); +} + + + +function Getcounterid($LineCounter) +{ + $this->db->select('*'); + $this->db->from('T_Action_Counter_Measure'); + $this->db->where('CounterId',$LineCounter); + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); +} + + +function DeleteAction($DelId) +{ + $this->db->where('DispositionId', $DelId); + $this->db->delete('T_Action_Disposition'); + //print_r($this->db->last_query()); + return TRUE; +} + + +function DeleteRoot($DelId) +{ + $this->db->where('RootId', $DelId); + $this->db->delete('T_RootCause'); + //print_r($this->db->last_query()); + return TRUE; +} + + +function DeleteCounter($DelId) +{ + $this->db->where('CounterId', $DelId); + $this->db->delete('T_Action_Counter_Measure'); + //print_r($this->db->last_query()); + return TRUE; +} + + +/*------------------------------------------------------------------------------*/ + +function updatefile($bill,$Picture,$oldfile) +{ + + // if($oldfile != ''){ + // //unlink("uploads/BillFiles/".$oldfile);//this deletes the file on particular folder too + // } + +$this->db->set('FilePath', $Picture); //value that used to update column +$this->db->where('BillNo', $bill); //which row want to upgrade +$this->db->update('T_PurchaseOrder_BillUpload'); +$afftectedRows = $this->db->affected_rows(); +return $afftectedRows; + +} + + + +// function newlogpo($logpo) +// { + +// $this->db->trans_start(); +// $this->db->insert('T_ponewlogs_Details',$logpo); +// $insert_id = $this->db->affected_rows(); +// $this->db->trans_complete(); +// return $insert_id; + + +// // $this->db->trans_start(); +// // $this->db->insert('T_polog_Details',$logpo); +// // $insert_id = $this->db->affected_rows(); +// // $this->db->trans_complete(); +// // return $insert_id; + +// } + + + +function insertlogpo($logpo){ + + + + + // $this->db->where('MaterialCode',$MaterialCode,'LineItemNos',$POLineItemNo); + // $this->db->update('T_ponewlogs_Details',$logpo); + $this->db->trans_start(); + $this->db->insert('T_polog_Details',$logpo); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + return $insert_id; + +} +function getlogpodtl($PONO){ + + + + + + +// $SQL = "select distinct log.PONO as LPONO, +// case +// WHEN log.Quantity <> pl.Quantity THEN log.Quantity +// else '-' +// ENd as Lqty, + +// case +// WHEN log.SupplierID <> pm.SupplierID THEN sup.Suppliername +// else '-' +// ENd as LSuppid, +// case +// WHEN log.Date <> pm.PODate THEN log.Date +// else '-' +// ENd as logDate , +// case +// WHEN log.Rate <> pl.Rate THEN log.Rate +// else '-' +// ENd as logRate , + + +// log.LineItemNos,log.MaterialCode,log.UpdatedOn,log.UpdateBy,emp.FirstName + + +// from T_ponewlogs_Details log +// join T_PurchaseOrder_LineItem pl on log.LineItemNos = pl.LineItemNo +// join T_PurchaseOrder_Master pm on pm.PONO = log.PONO +// join tbl_users user on user.userId = log.UpdateBy +// left join T_Employee_Details emp on emp.EmpID= user.EmpID +// left join T_SupplierDetailsN sup on sup.SupplierID = log.SupplierID +// where log.PONO ='".$PONO."'"; + + + +$SQL = "select log.*,sup.SupplierName,emp.FirstName from + T_polog_Details log + join tbl_users user on user.userId = log.UpdateBy + left join T_Employee_Details emp on emp.EmpID= user.EmpID + left join T_SupplierDetailsN sup on sup.SupplierID = log.oldValue + where PONO ='".$PONO."'"; + + +$logpodtl = $this->db->query($SQL); + + return $logpodtl->result(); +} + + + // function EditpoValues($pono) + // { + // $this->db->select('*'); + // $this->db->from('T_ponewlogs_Details'); + // $this->db->where('PONO',$pono); + // // $this->db->where('MaterialCode',$materialcode); + // $query = $this->db->get(); + // return $query->result_array(); + // } + + + function insertfile($filelist) + { + + //print_r($myfile);die; + + $this->db->insert('T_PurchaseOrder_BillUpload',$filelist); + $myfile=$this->db->affected_rows(); + return $myfile; + } + +/*------------------------------------------------------------------------------*/ + +function updateigrM($PONO,$IGRNo,$igrMaster){ + + //print_r($igrMaster);die; + $this->db->where('PONO',$PONO); + $this->db->where('IGRNO',$IGRNo); + + $this->db->update('T_IGR_Master',$igrMaster); + + $r = $this->db->affected_rows(); + return $r; +} +function getigrno($bill){ + + $subQuery ='select bill.BillNo,IGR.IGRNO, IGR.PONO FROM T_IGR_Master IGR + join T_PurchaseOrder_BillUpload bill on bill.IGRNO = IGR.IGRNO + where bill.BillNO = ? '; + + $query = $this->db->query($subQuery,array($bill)); + + return $query->result_array(); + } + /*** ----------------------------- */ } \ No newline at end of file diff --git a/application/models/purchaseorder_model.php~ b/application/models/purchaseorder_model.php~ index f72a134a..21cc2c04 100644 --- a/application/models/purchaseorder_model.php~ +++ b/application/models/purchaseorder_model.php~ @@ -451,8 +451,7 @@ function purchaseorderListing($forwhat='') // print_r($this->db->last_query()); if($insert_id>0) { - // $subQuery = 'select max(PONO) as PONO from T_PurchaseOrder_Master'; - $subQuery = 'select PONO from T_PurchaseOrder_Master order by CreatedDate desc limit 1'; + $subQuery = 'select max(PONO) as PONO from T_PurchaseOrder_Master'; $query = $this->db->query($subQuery); @@ -491,8 +490,7 @@ function purchaseorderListing($forwhat='') // print_r($this->db->last_query()); if($insert_id>0) { - //$subQuery = 'select max(LineItemNo) as LineItemNo from T_PurchaseOrder_LineItem'; - $subQuery = 'select LineItemNo from T_PurchaseOrder_LineItem order by CreatedDate desc limit 1'; + $subQuery = 'select max(LineItemNo) as LineItemNo from T_PurchaseOrder_LineItem'; $query = $this->db->query($subQuery); diff --git a/application/models/requistion_model.php b/application/models/requistion_model.php index 4d91722f..67e821e5 100644 --- a/application/models/requistion_model.php +++ b/application/models/requistion_model.php @@ -547,4 +547,4 @@ ifnull(Po.Quantity,0) as POQTY,sta.StatusName } - \ No newline at end of file + diff --git a/application/models/requistion_model.php~ b/application/models/requistion_model.php~ index f4d3e491..24c437bf 100644 --- a/application/models/requistion_model.php~ +++ b/application/models/requistion_model.php~ @@ -350,7 +350,7 @@ class requistion_model extends CI_Model $this->db->trans_complete(); if($insert_id>0) { - $subQuery = 'select ReqNo from T_Requestion_Master order by CreatedDate desc limit 1'; + $subQuery = 'select max(ReqNo) as ReqNo from T_Requestion_Master'; $query = $this->db->query($subQuery); diff --git a/application/models/storerequistion_model.php b/application/models/storerequistion_model.php index f8bbab87..46cacaf8 100644 --- a/application/models/storerequistion_model.php +++ b/application/models/storerequistion_model.php @@ -1,507 +1,507 @@ -db->select ('ED.FirstName,CM.CostCenterCode,CM.CostCenterName,CB.BudgetAmount,CB.BudgetType'); - $this->db-> from(' T_CostCenter_Master CM'); - $this->db->join ('T_CostCenter_Departments CD ',' CD.CostCenterCode = CM.CostCenterCode'); - $this->db->join ('T_CostCenter_Budget CB ',' CB.CostCenterCode = CM.CostCenterCode'); - $this->db->join ('T_Employee_Details ED ','ED.Departmentcode = CD.DEPCode'); - $this->db->join ('tbl_users TU ',' TU.EmpID = ED.EmpID '); - $this->db->where('TU.userId ',$userId); - //$this->db->where('CB.BudgetType','SERVICE'); - - $query = $this->db->get(); - $result = $query->result(); - //print_r( $result ); - - return $result; - - } - - - function getRawMaterialList($MaterialCode='') - { - $this->db->select('MaterialName,UOM,MaterialCode'); - $this->db->from('T_MaterialMaster'); - //$this->db->where('MaterialCode',$MaterialCode ); - $query = $this->db->get(); - $result = $query->result(); - // print_r($result); - return $result; - } - -/** - * This function is used to add the Raise store Requestion into the Database - * @return array $result : This is result of the query - */ - function addRequistion($ReqDate='') - { - - $this->db->trans_start(); - $this->db->insert('T_Store_Requestion_Master', $ReqDate); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - if($insert_id>0) - { - $subQuery = 'select StoreReqNo from T_Store_Requestion_Master order by CreatedDate desc limit 1'; - - $query = $this->db->query($subQuery); - - return $query->result_array(); - } - - //return $insert_id; - - } - - /** - * This function is used to update the details into Database - * @return array $result : This is result of the query - */ - function UpdateRequistion($StoreReqNo,$Request) - { - $this->db->where('StoreReqNo',$StoreReqNo); - $this->db->update('T_Store_Requestion_Master',$Request); - return TRUE; - } - - function getRequistionList() - { - $this->db->select('Sm.StoreReqNo, Emp.FirstName as Requestedby,Sm.ReqDate,Sm.Status,Sm.Comments as Remarks,St.StatusName,Dept.DepartmentName '); - $this->db->from ('T_Store_Requestion_Master Sm'); - $this->db->join('tbl_users user','Sm.CreatedBy = user.userId '); - $this->db->join('T_Employee_Details Emp','Emp.EmpID= user.EmpID'); - $this->db->join('T_DepartmentDetails Dept','Dept.DEPCode = Sm.DepartmentCode'); - $this->db->join('T_Status St','St.StatusCode = Sm.Status'); - $this->db->where('Sm.Status ',STORE_APPROVAL); - $this->db->or_where('Sm.Status ',STORE_PARTIALLYISSUSED); - - $query = $this->db->get(); - $result = $query->result(); - - // print_r($this->db->last_query()); - //print_r($result); - return $result; - - } - -/*this function used to Add Store Requistion*/ - function addstoreRequistion($Request) - { - //print_r($Request); - //die(); - $this->db->trans_start(); - $this->db->insert('T_Store_Requestion_Details',$Request); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - if($insert_id>0) - { - $subQuery = 'select max(StoreReqLineItemNo) as StoreReqLineItemNo from T_Store_Requestion_Details'; - - $query = $this->db->query($subQuery); - - return $query->result_array(); - } - - - } - -/*this function used to Update Store Requistion*/ - function upstoreRequistion($Request) - { - //print_r($Request); - $this->db->trans_start(); - $this->db->update('T_Store_Requestion_Details',$Request); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - if($insert_id>0) - { - $subQuery = 'select max(StoreReqLineItemNo) as StoreReqLineItemNo from T_Store_Requestion_Details'; - - $query = $this->db->query($subQuery); - - return $query->result_array(); - } - /** - * This function is used to check the Request Line Item is in Draft status - * @return array $result : This is result of the query - */ - function LineItemIsExists($StoreReqNo,$MaterialCode) - { - $this->db->select('StoreReqNo'); - $this->db->from('T_Store_Requestion_Details'); - $this->db->where('StoreReqNo ',$StoreReqNo ); - $this->db->where('MaterialCode ',$MaterialCode ); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - //echo $result->num_rows; - return $query->result_array(); - } - } - - } - - - - - - - /** - * This function is used to add the Line item details to the Database - * @return array $result : This is result of the query - */ - function addRequistionDetails($StoreReqLineItemNo) - { - //echo "nsmdnsjkkjasdf"; die(); - $this->db->trans_start(); - $this->db->insert('T_Store_Requestion_Details', $StoreReqLineItemNo - ); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - //print_r($this->db->last_query()); - return $insert_id; - - } - - /** - * This function is used to update the Line item details to the Database - * @return array $result : This is result of the query - */ - function upRequistionDetails($StoreReqLineItemNo) - { - //echo "nsmdnsjkkjasdf"; die(); - $this->db->trans_start(); - $this->db->update('T_Store_Requestion_Details', $StoreReqLineItemNo - ); - $insert_id = $this->db->affected_rows(); - $this->db->trans_complete(); - //print_r($this->db->last_query()); - return $insert_id; - - } - - - - /** - * This function is used to check the Request Line Item is in Draft status - * @return array $result : This is result of the query - */ - function LineItemIsExists($StoreReqNo,$MaterialCode) - { - $this->db->select('StoreReqNo'); - $this->db->from('T_Store_Requestion_Details'); - $this->db->where('StoreReqNo ',$StoreReqNo ); - $this->db->where('MaterialCode ',$MaterialCode ); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - //echo $result->num_rows; - return $query->result_array(); - } - } - - /** - * This function is used to update the details into Database - * @return array $result : This is result of the query - */ - function UpdateRequistionLineItem($Request,$StoreReqNo,$MaterialCode) - { - $this->db->where('StoreReqNo', $StoreReqNo); - $this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_Store_Requestion_Details',($Request)); - - return TRUE; - } - /** - * This function is used to delete the Line item from details into Database - * @return array $result : This is result of the query - */ - function DeleteRequistionLineItem( $StoreReqNo,$MaterialCode) - { - $this->db->where('StoreReqNo', $StoreReqNo); - $this->db->where('MaterialCode', $MaterialCode); - $this->db->delete('T_Store_Requestion_Details'); - - return TRUE; - } - - - - /** - * This function is used to get the userId information - * @return array $result : This is result of the query - */ - function getStatus() - { - $this->db->select('StatusCode,StatusName '); - $this->db->from('T_Status'); - $this->db->where('Remarks', 'STORE REQUISTION STATUS'); - //$this->db->where('StatusCode!=', REQ_DRAFT); - $query = $this->db->get(); - // print_r($query); - return $query->result(); - } - - - function editstorerequistions($StoreReqNo) - { - - $this->db->select('Sr.StoreReqNo,Sr.MaterialCode,Sr.QuantityRequired,Sr.Status,Sr.Remarks,Mm.MaterialName,Mm.UOM,Sr.QuantityIssued,STM.Status '); - $this->db->from('T_Store_Requestion_Details Sr'); - $this->db->join('T_MaterialMaster Mm' ,' Mm.MaterialCode = Sr.MaterialCode'); - $this->db->join('T_Store_Requestion_Master STM' ,' STM.StoreReqNo = Sr.StoreReqNo'); - $this->db->where('Sr.StoreReqNo',$StoreReqNo); - $query = $this->db->get(); - return $query->result(); - } - - - /** - * This function is used to check the Request is in Draft status - * @return array $result : This is result of the query - */ - function RequistionIsExists($ReqDate) - { - $this->db->select('StoreReqNo'); - $this->db->from('T_Store_Requestion_Master'); - //$this->db->where('Status ',REQ_DRAFT ); - $this->db->where('ReqDate',$ReqDate ); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - //echo $result->num_rows; - return $query->result_array(); - } - } - /** - * This function is used to check the Request is in Draft status - * @return array $result : This is result of the query - */ - function Storerequisition($MaterialCode) - { - $this->db->select('StoreReqNo'); - $this->db->from('T_Store_Requestion_Details'); - //$this->db->where('Status ',REQ_DRAFT ); - $this->db->where('MaterialCode',$MaterialCode); - $query = $this->db->get(); - - if ($query->num_rows > 0) { - //echo $result->num_rows; - return $query->result_array(); - } - } - - /** COMPLETED - * This function is used to get the List of Store Requist details to the approver - * @return array $result : This is result of the query - */ - function getApproverRequistList($UserID) - { - // echo 'UserId: '.$UserID . 'From: '.$FromDate .'TO: '. $ToDate. 'Status: '. $Status; - - - $subQuery = ' select distinct Str.StoreReqNo,Str.Requestedby,Str.ReqDate,Str.Status,Str.CreatedDate,Str.Comments,St.StatusName,Emp1.FirstName - from T_Store_Requestion_Master Str - join T_Status St on St.StatusCode = Str.Status - join T_Employee_Details Emp on Emp.Departmentcode =Str.DepartmentCode - join T_Employee_Details Emp1 on Emp1.EmpID =Str.Requestedby - join T_DepartmentDetails Dept on Dept.DEPCode = Emp.Departmentcode - where Str.Status not in(?,?,?) and Emp.Departmentcode in (select DEPCode from T_DepartmentDetails where HeadDept= - (select HeadDept from T_DepartmentDetails where DEPCode = (select Departmentcode from T_Employee_Details where - EmpID=(select EmpID from tbl_users where userId=?))))'; - - $query =''; - - - $query = $this->db->query($subQuery, array(STORE_REJECT,STORE_DRAFT,REQ_DELETED,$UserID)); - - - // print_r($this->db->last_query()); - return $query->result(); - } - /** - * This function is used to get the Store Requsition List for the login user - * @return array $result : This is result of the query - */ - function getRequistDetails($StoreReqNo='') - { - - $subQuery = ' select Str.StoreReqNo,Str.Requestedby,Str.ReqDate,Dept.DEPCode,Dept.DepartmentName,Cm.CostCenterCode,Cm.CostCenterName,Emp.FirstName from T_Store_Requestion_Master Str - join T_DepartmentDetails Dept on Dept.DEPCode = Str.DepartmentCode - join T_CostCenter_Master Cm on Cm.CostCenterCode =Str.CostCenterCode - join T_Employee_Details Emp on Emp.EmpID =Str.Requestedby - where StoreReqNo =? '; - - - - $query = $this->db->query($subQuery, array($StoreReqNo)); - // print_r($this->db->last_query()); - return $query->result(); - - } - function editRequistDetails($StoreReqNo) - { -$this->db->select('StoreReqNo,Sr.CostCenterCode,Cc.CostCenterName - '); - $this->db->from('T_Store_Requestion_Master Sr'); - $this->db->join('T_CostCenter_Master Cc ',' Cc.CostCenterCode=Sr.CostCenterCode'); - $this->db->where('StoreReqNo',$StoreReqNo); - $query = $this->db->get(); - return $query->result(); - - - } - -/** - * This function is used to get the Store Requsition List for the login user - * @return array $result : This is result of the query - */ - function getRequistItemListApproval($StoreReqNo,$NoArray='') - { - - $subQuery = ' select Str.StoreReqNo,Str.MaterialCode,Str.QuantityRequired,Str.Remarks,Mat.MaterialName,Mat.UOM,Ss.StatusName,Str.Status,Str.QuantityIssued - from T_Store_Requestion_Details Str - join T_MaterialMaster Mat on Mat.MaterialCode = Str.MaterialCode - join T_Status Ss on Ss.StatusCode = Str.Status - where Str.StoreReqNo =?'; - - - - - $query = $this->db->query($subQuery, array($StoreReqNo)); - if($NoArray == '') - { - return $query->result_array(); - } - else - { - return $query->result(); - } - } - - /** - * This function is used to get the Store Requsition List for the login user - * @return array $result : This is result of the query - */ - function getRequistItemList($StoreReqNo) - { - - $subQuery = ' select Str.StoreReqNo,Str.MaterialCode,Str.QuantityRequired,Str.QuantityIssued,Str.Remarks,Str.StoreComments,Mat.MaterialName,Mat.UOM,Ss.StatusName,St.Status,St.Quantity - from T_Store_Requestion_Details Str - join T_MaterialMaster Mat on Mat.MaterialCode = Str.MaterialCode - join T_Status Ss on Ss.StatusCode = Str.Status - left join T_Store_Stockdetails St on St.MaterialCode=Str.MaterialCode - where Str.StoreReqNo =?'; - - - - - $query = $this->db->query($subQuery, array($StoreReqNo)); - //print_r($this->db->last_query()); - - - return $query->result(); - - } - - function getStoreRequistionStatus($StreReqNo='') - { - $this->db->select('Status'); - $this->db->from('T_Store_Requestion_Master Sr'); - - $this->db->where('StoreReqNo',$StreReqNo); - $query = $this->db->get(); - return $query->result(); - } - - function UpdateStoreRequistionItem($Items,$ReqNo,$MaterialCode) - { - $this->db->where('StoreReqNo', $ReqNo); - $this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_Store_Requestion_Details', $Items); - - return TRUE; - - } - - -function getSavedQty($ReqNO,$MaterialCode) -{ - $subQuery='select QuantityIssued from T_Store_Requestion_Details - where StoreReqNo=? and MaterialCode=?'; - - $query = $this->db->query($subQuery, array($ReqNO,$MaterialCode)); - return $query->result(); -} - - - - -function updatestoremaster($updatestatus,$StoreReqNo) -{ - $this->db->where('StoreReqNo', $StoreReqNo); - $this->db->update('T_Store_Requestion_Master', $updatestatus); - - return TRUE; -} - -function getstatuscount($Status,$StoreReqNo) -{ - $this->db->select('count(Status) as SCount'); - $this->db->from('T_Store_Requestion_Details'); - - $this->db->where('Status', $Status); - $this->db->where('StoreReqNo',$StoreReqNo); - //$this->db->where('StoreReqNo', $StoreReqNo); - - $query = $this->db->get(); - //print_r($this->db->last_query()); - return $query->result(); -} - - - /*this function used to get the all store requistion list view*/ - function Storeall($StoreReqNo,$IsArray='') - { - - $result = $this->db-> query("CALL P_GET_AllSTOREREQUISTION('".$StoreReqNo."')") or die(mysql_error()); - - { - //echo 'Store Line item Inserted successfully'; - if($IsArray != '') - { - - return $result->result_array(); - } - else - { - return $result->result(); - } - } - } - - - function getItemQuantityFromStock($MaterialCode) - { - - - $subQuery = 'select Quantity from T_Store_Stockdetails where MaterialCode=?'; - $query = $this->db->query($subQuery,array($MaterialCode)); - return $query->result_array(); - } - - function UpdateStock($StockDetails,$MaterialCode) - { - - $this->db->where('MaterialCode', $MaterialCode); - $this->db->update('T_Store_Stockdetails', $StockDetails); - - return TRUE; - } +db->select ('ED.FirstName,CM.CostCenterCode,CM.CostCenterName,CB.BudgetAmount,CB.BudgetType'); + $this->db-> from(' T_CostCenter_Master CM'); + $this->db->join ('T_CostCenter_Departments CD ',' CD.CostCenterCode = CM.CostCenterCode'); + $this->db->join ('T_CostCenter_Budget CB ',' CB.CostCenterCode = CM.CostCenterCode'); + $this->db->join ('T_Employee_Details ED ','ED.Departmentcode = CD.DEPCode'); + $this->db->join ('tbl_users TU ',' TU.EmpID = ED.EmpID '); + $this->db->where('TU.userId ',$userId); + //$this->db->where('CB.BudgetType','SERVICE'); + + $query = $this->db->get(); + $result = $query->result(); + //print_r( $result ); + + return $result; + + } + + + function getRawMaterialList($MaterialCode='') + { + $this->db->select('MaterialName,UOM,MaterialCode'); + $this->db->from('T_MaterialMaster'); + //$this->db->where('MaterialCode',$MaterialCode ); + $query = $this->db->get(); + $result = $query->result(); + // print_r($result); + return $result; + } + +/** + * This function is used to add the Raise store Requestion into the Database + * @return array $result : This is result of the query + */ + function addRequistion($ReqDate='') + { + + $this->db->trans_start(); + $this->db->insert('T_Store_Requestion_Master', $ReqDate); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + if($insert_id>0) + { + $subQuery = 'select StoreReqNo from T_Store_Requestion_Master order by CreatedDate desc limit 1'; + + $query = $this->db->query($subQuery); + + return $query->result_array(); + } + + //return $insert_id; + + } + + /** + * This function is used to update the details into Database + * @return array $result : This is result of the query + */ + function UpdateRequistion($StoreReqNo,$Request) + { + $this->db->where('StoreReqNo',$StoreReqNo); + $this->db->update('T_Store_Requestion_Master',$Request); + return TRUE; + } + + function getRequistionList() + { + $this->db->select('Sm.StoreReqNo, Emp.FirstName as Requestedby,Sm.ReqDate,Sm.Status,Sm.Comments as Remarks,St.StatusName,Dept.DepartmentName '); + $this->db->from ('T_Store_Requestion_Master Sm'); + $this->db->join('tbl_users user','Sm.CreatedBy = user.userId '); + $this->db->join('T_Employee_Details Emp','Emp.EmpID= user.EmpID'); + $this->db->join('T_DepartmentDetails Dept','Dept.DEPCode = Sm.DepartmentCode'); + $this->db->join('T_Status St','St.StatusCode = Sm.Status'); + $this->db->where('Sm.Status ',STORE_APPROVAL); + $this->db->or_where('Sm.Status ',STORE_PARTIALLYISSUSED); + + $query = $this->db->get(); + $result = $query->result(); + + // print_r($this->db->last_query()); + //print_r($result); + return $result; + + } + +/*this function used to Add Store Requistion*/ + function addstoreRequistion($Request) + { + //print_r($Request); + //die(); + $this->db->trans_start(); + $this->db->insert('T_Store_Requestion_Details',$Request); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + if($insert_id>0) + { + $subQuery = 'select max(StoreReqLineItemNo) as StoreReqLineItemNo from T_Store_Requestion_Details'; + + $query = $this->db->query($subQuery); + + return $query->result_array(); + } + + + } + +/*this function used to Update Store Requistion*/ + function upstoreRequistion($Request) + { + //print_r($Request); + $this->db->trans_start(); + $this->db->update('T_Store_Requestion_Details',$Request); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + if($insert_id>0) + { + $subQuery = 'select max(StoreReqLineItemNo) as StoreReqLineItemNo from T_Store_Requestion_Details'; + + $query = $this->db->query($subQuery); + + return $query->result_array(); + } + /** + * This function is used to check the Request Line Item is in Draft status + * @return array $result : This is result of the query + */ + function LineItemIsExists($StoreReqNo,$MaterialCode) + { + $this->db->select('StoreReqNo'); + $this->db->from('T_Store_Requestion_Details'); + $this->db->where('StoreReqNo ',$StoreReqNo ); + $this->db->where('MaterialCode ',$MaterialCode ); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + //echo $result->num_rows; + return $query->result_array(); + } + } + + } + + + + + + + /** + * This function is used to add the Line item details to the Database + * @return array $result : This is result of the query + */ + function addRequistionDetails($StoreReqLineItemNo) + { + //echo "nsmdnsjkkjasdf"; die(); + $this->db->trans_start(); + $this->db->insert('T_Store_Requestion_Details', $StoreReqLineItemNo + ); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + //print_r($this->db->last_query()); + return $insert_id; + + } + + /** + * This function is used to update the Line item details to the Database + * @return array $result : This is result of the query + */ + function upRequistionDetails($StoreReqLineItemNo) + { + //echo "nsmdnsjkkjasdf"; die(); + $this->db->trans_start(); + $this->db->update('T_Store_Requestion_Details', $StoreReqLineItemNo + ); + $insert_id = $this->db->affected_rows(); + $this->db->trans_complete(); + //print_r($this->db->last_query()); + return $insert_id; + + } + + + + /** + * This function is used to check the Request Line Item is in Draft status + * @return array $result : This is result of the query + */ + function LineItemIsExists($StoreReqNo,$MaterialCode) + { + $this->db->select('StoreReqNo'); + $this->db->from('T_Store_Requestion_Details'); + $this->db->where('StoreReqNo ',$StoreReqNo ); + $this->db->where('MaterialCode ',$MaterialCode ); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + //echo $result->num_rows; + return $query->result_array(); + } + } + + /** + * This function is used to update the details into Database + * @return array $result : This is result of the query + */ + function UpdateRequistionLineItem($Request,$StoreReqNo,$MaterialCode) + { + $this->db->where('StoreReqNo', $StoreReqNo); + $this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_Store_Requestion_Details',($Request)); + + return TRUE; + } + /** + * This function is used to delete the Line item from details into Database + * @return array $result : This is result of the query + */ + function DeleteRequistionLineItem( $StoreReqNo,$MaterialCode) + { + $this->db->where('StoreReqNo', $StoreReqNo); + $this->db->where('MaterialCode', $MaterialCode); + $this->db->delete('T_Store_Requestion_Details'); + + return TRUE; + } + + + + /** + * This function is used to get the userId information + * @return array $result : This is result of the query + */ + function getStatus() + { + $this->db->select('StatusCode,StatusName '); + $this->db->from('T_Status'); + $this->db->where('Remarks', 'STORE REQUISTION STATUS'); + //$this->db->where('StatusCode!=', REQ_DRAFT); + $query = $this->db->get(); + // print_r($query); + return $query->result(); + } + + + function editstorerequistions($StoreReqNo) + { + + $this->db->select('Sr.StoreReqNo,Sr.MaterialCode,Sr.QuantityRequired,Sr.Status,Sr.Remarks,Mm.MaterialName,Mm.UOM,Sr.QuantityIssued,STM.Status '); + $this->db->from('T_Store_Requestion_Details Sr'); + $this->db->join('T_MaterialMaster Mm' ,' Mm.MaterialCode = Sr.MaterialCode'); + $this->db->join('T_Store_Requestion_Master STM' ,' STM.StoreReqNo = Sr.StoreReqNo'); + $this->db->where('Sr.StoreReqNo',$StoreReqNo); + $query = $this->db->get(); + return $query->result(); + } + + + /** + * This function is used to check the Request is in Draft status + * @return array $result : This is result of the query + */ + function RequistionIsExists($ReqDate) + { + $this->db->select('StoreReqNo'); + $this->db->from('T_Store_Requestion_Master'); + //$this->db->where('Status ',REQ_DRAFT ); + $this->db->where('ReqDate',$ReqDate ); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + //echo $result->num_rows; + return $query->result_array(); + } + } + /** + * This function is used to check the Request is in Draft status + * @return array $result : This is result of the query + */ + function Storerequisition($MaterialCode) + { + $this->db->select('StoreReqNo'); + $this->db->from('T_Store_Requestion_Details'); + //$this->db->where('Status ',REQ_DRAFT ); + $this->db->where('MaterialCode',$MaterialCode); + $query = $this->db->get(); + + if ($query->num_rows > 0) { + //echo $result->num_rows; + return $query->result_array(); + } + } + + /** COMPLETED + * This function is used to get the List of Store Requist details to the approver + * @return array $result : This is result of the query + */ + function getApproverRequistList($UserID) + { + // echo 'UserId: '.$UserID . 'From: '.$FromDate .'TO: '. $ToDate. 'Status: '. $Status; + + + $subQuery = ' select distinct Str.StoreReqNo,Str.Requestedby,Str.ReqDate,Str.Status,Str.CreatedDate,Str.Comments,St.StatusName,Emp1.FirstName + from T_Store_Requestion_Master Str + join T_Status St on St.StatusCode = Str.Status + join T_Employee_Details Emp on Emp.Departmentcode =Str.DepartmentCode + join T_Employee_Details Emp1 on Emp1.EmpID =Str.Requestedby + join T_DepartmentDetails Dept on Dept.DEPCode = Emp.Departmentcode + where Str.Status not in(?,?,?) and Emp.Departmentcode in (select DEPCode from T_DepartmentDetails where HeadDept= + (select HeadDept from T_DepartmentDetails where DEPCode = (select Departmentcode from T_Employee_Details where + EmpID=(select EmpID from tbl_users where userId=?))))'; + + $query =''; + + + $query = $this->db->query($subQuery, array(STORE_REJECT,STORE_DRAFT,REQ_DELETED,$UserID)); + + + // print_r($this->db->last_query()); + return $query->result(); + } + /** + * This function is used to get the Store Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistDetails($StoreReqNo='') + { + + $subQuery = ' select Str.StoreReqNo,Str.Requestedby,Str.ReqDate,Dept.DEPCode,Dept.DepartmentName,Cm.CostCenterCode,Cm.CostCenterName,Emp.FirstName from T_Store_Requestion_Master Str + join T_DepartmentDetails Dept on Dept.DEPCode = Str.DepartmentCode + join T_CostCenter_Master Cm on Cm.CostCenterCode =Str.CostCenterCode + join T_Employee_Details Emp on Emp.EmpID =Str.Requestedby + where StoreReqNo =? '; + + + + $query = $this->db->query($subQuery, array($StoreReqNo)); + // print_r($this->db->last_query()); + return $query->result(); + + } + function editRequistDetails($StoreReqNo) + { +$this->db->select('StoreReqNo,Sr.CostCenterCode,Cc.CostCenterName + '); + $this->db->from('T_Store_Requestion_Master Sr'); + $this->db->join('T_CostCenter_Master Cc ',' Cc.CostCenterCode=Sr.CostCenterCode'); + $this->db->where('StoreReqNo',$StoreReqNo); + $query = $this->db->get(); + return $query->result(); + + + } + +/** + * This function is used to get the Store Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistItemListApproval($StoreReqNo,$NoArray='') + { + + $subQuery = ' select Str.StoreReqNo,Str.MaterialCode,Str.QuantityRequired,Str.Remarks,Mat.MaterialName,Mat.UOM,Ss.StatusName,Str.Status,Str.QuantityIssued + from T_Store_Requestion_Details Str + join T_MaterialMaster Mat on Mat.MaterialCode = Str.MaterialCode + join T_Status Ss on Ss.StatusCode = Str.Status + where Str.StoreReqNo =?'; + + + + + $query = $this->db->query($subQuery, array($StoreReqNo)); + if($NoArray == '') + { + return $query->result_array(); + } + else + { + return $query->result(); + } + } + + /** + * This function is used to get the Store Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistItemList($StoreReqNo) + { + + $subQuery = ' select Str.StoreReqNo,Str.MaterialCode,Str.QuantityRequired,Str.QuantityIssued,Str.Remarks,Str.StoreComments,Mat.MaterialName,Mat.UOM,Ss.StatusName,St.Status,St.Quantity + from T_Store_Requestion_Details Str + join T_MaterialMaster Mat on Mat.MaterialCode = Str.MaterialCode + join T_Status Ss on Ss.StatusCode = Str.Status + left join T_Store_Stockdetails St on St.MaterialCode=Str.MaterialCode + where Str.StoreReqNo =?'; + + + + + $query = $this->db->query($subQuery, array($StoreReqNo)); + //print_r($this->db->last_query()); + + + return $query->result(); + + } + + function getStoreRequistionStatus($StreReqNo='') + { + $this->db->select('Status'); + $this->db->from('T_Store_Requestion_Master Sr'); + + $this->db->where('StoreReqNo',$StreReqNo); + $query = $this->db->get(); + return $query->result(); + } + + function UpdateStoreRequistionItem($Items,$ReqNo,$MaterialCode) + { + $this->db->where('StoreReqNo', $ReqNo); + $this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_Store_Requestion_Details', $Items); + + return TRUE; + + } + + +function getSavedQty($ReqNO,$MaterialCode) +{ + $subQuery='select QuantityIssued from T_Store_Requestion_Details + where StoreReqNo=? and MaterialCode=?'; + + $query = $this->db->query($subQuery, array($ReqNO,$MaterialCode)); + return $query->result(); +} + + + + +function updatestoremaster($updatestatus,$StoreReqNo) +{ + $this->db->where('StoreReqNo', $StoreReqNo); + $this->db->update('T_Store_Requestion_Master', $updatestatus); + + return TRUE; +} + +function getstatuscount($Status,$StoreReqNo) +{ + $this->db->select('count(Status) as SCount'); + $this->db->from('T_Store_Requestion_Details'); + + $this->db->where('Status', $Status); + $this->db->where('StoreReqNo',$StoreReqNo); + //$this->db->where('StoreReqNo', $StoreReqNo); + + $query = $this->db->get(); + //print_r($this->db->last_query()); + return $query->result(); +} + + + /*this function used to get the all store requistion list view*/ + function Storeall($StoreReqNo,$IsArray='') + { + + $result = $this->db-> query("CALL P_GET_AllSTOREREQUISTION('".$StoreReqNo."')") or die(mysql_error()); + + { + //echo 'Store Line item Inserted successfully'; + if($IsArray != '') + { + + return $result->result_array(); + } + else + { + return $result->result(); + } + } + } + + + function getItemQuantityFromStock($MaterialCode) + { + + + $subQuery = 'select Quantity from T_Store_Stockdetails where MaterialCode=?'; + $query = $this->db->query($subQuery,array($MaterialCode)); + return $query->result_array(); + } + + function UpdateStock($StockDetails,$MaterialCode) + { + + $this->db->where('MaterialCode', $MaterialCode); + $this->db->update('T_Store_Stockdetails', $StockDetails); + + return TRUE; + } } \ No newline at end of file diff --git a/application/models/zohobook_api_model.php b/application/models/zohobook_api_model.php new file mode 100644 index 00000000..8fc319de --- /dev/null +++ b/application/models/zohobook_api_model.php @@ -0,0 +1,78 @@ +db->select(); + $this->db->from('ip_tax_rates'); + $this->db->where('tax_rate_percent', $gst); + $query = $this->db->get(); + $query = $query->result_array(); + return $query; + } + + public function ip_clients($gst_no) + { + $this->db->select(); + $this->db->from('ip_clients'); + $this->db->where('client_tax_code', $gst_no); + $query = $this->db->get(); + $query = $query->result_array(); + return $query; + } + + public function ip_products($sku) + { + $this->db->select(); + $this->db->from('ip_products'); + $this->db->where('sku', $sku); + $query = $this->db->get(); + $query = $query->result_array(); + return $query; + } + + public function ip_invoices($invoice_number , $invoice_date) + { + $this->db->select(); + $this->db->from('ip_invoices'); + $this->db->where('invoice_number', $invoice_number); + $this->db->where('invoice_date_created', $invoice_date); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + public function insert($data,$table) + { + $this->db->insert($table,$data); + return $this->db->insert_id(); + } + + function sql_invoice_update($action, $invoice_number, $invoice_date_created ,$table) + { + // echo 'model'; + // print_r($action); + // echo '
    '; + $this->db->where('invoice_number',$invoice_number); + $this->db->where('invoice_date_created',$invoice_date_created); + $this->db->update($table,$action); + return true; + } + + function get_data($table ,$col_name ,$id) + { + $this->db->select(); + $this->db->from($table); + $this->db->where($col_name , $id); + $query = $this->db->get(); + $query = $query->result_array(); + return $query; + } + + function update($action,$id,$table){ + $this->db->where('id',$id); + $this->db->update($table,$action); + } + + +} \ No newline at end of file diff --git a/application/views/reportmasterlist.php b/application/views/reportmasterlist.php index 7758b38b..4b743648 100644 --- a/application/views/reportmasterlist.php +++ b/application/views/reportmasterlist.php @@ -1,170 +1,170 @@ - - -
    - -
    -

    -
    Product Test Reports List
    -

    -
    -
    - - - -
    -
    -
    -
    - -
    - -
    - Add New -
    - - - -
    - -
    - - -
    - - -
    - - - - - - - - - - - - - - - -
    "; - ?> - - - -
    Test Report IDInvoice IDBatch DateProduct NameCustomer Name
    testreport_id?>      - document)){?> - - - invoiceid?> batchdate),'d-m-Y');?>product_name;?>client_name;?>
    -

     

    -
    - -
    -
    - -
    -
    -
    -
    -
    - - - - - - + + + + + \ No newline at end of file diff --git a/application/views/viewindreportpdf.php b/application/views/viewindreportpdf.php index 4616aa9b..2dc9c34c 100644 --- a/application/views/viewindreportpdf.php +++ b/application/views/viewindreportpdf.php @@ -37,8 +37,6 @@ foreach($reportdata['company'] as $c) $pic = $c->ProfilePic; } } -// echo $pic;die; -// echo base_url().'uploads/images/'.$pic;die; ?>