load->model('inwardgateregister_model'); $this->load->library('session'); $this->load->library('form_validation'); $this->isLoggedIn(); $this->CompanyName = $this->global['CompanyName']; } /** * Index Page for this controller (default function of the class) */ public function index() { //$this->global['pageTitle'] = 'Resico : Inward Gate Register'; $this->global['pageTitle'] = $this->CompanyName.' : Inward Gate Register'; $this->loadViews("viewinwardgateregister", $this->global,NULL , NULL); } /** * To load the IGR details for View purpose. */ function viewIGRDetails() { $this->load->model('inwardgateregister_model'); //$this->global['pageTitle'] = 'Resico : Inward Gate Register Details'; $this->global['pageTitle'] = $this->CompanyName.' : Inward Gate Register Details'; $data['IGR']= $this->inwardgateregister_model->igrListing(); $this->loadViews("viewIGRDetails",$this->global,$data,NULL); } /** * For add new value for the system. */ function addinwardgateregister() { $this->load->model('inwardgateregister_model'); //$this->global['pageTitle'] = 'Resico : Add Inward Gate Register'; $this->global['pageTitle'] = $this->CompanyName.' : Inward Gate Register'; $data['PO_NO'] = $this->inwardgateregister_model->getpurchaseorder(); $this->loadViews("inwardgateregister", $this->global, $data, NULL); } /** * To Convert the dateformat (date with time) and stored into DB */ function getDateformat($Val) { $date = new DateTime($Val,new DateTimeZone('Asia/Kolkata')); $retDate = $date->format('Y-m-d H:i:s'); return $retDate; } /** * To display igr lineitem datas */ function IGRITEM() { $PO = $this->input->post('id'); $CreatedBy = $this->session->userdata('userId'); $this->inwardgateregister_model->UpdatePOMaster($PO,$CreatedBy); $data = $this->inwardgateregister_model->viewpurchaseorder($PO); echo json_encode($data); } /** * To upload IGR files */ function adfile() { $picture = ''; if(!empty($_FILES['file']['name'])) { $config['upload_path'] = 'uploads/Igrfiles/'; $config['allowed_types'] = '*'; $config['file_name'] =str_replace(" ","", $_FILES['file']['name']); //Load upload library and initialize configuration $this->load->library('upload',$config); $this->upload->initialize($config); if($this->upload->do_upload('file')) { $uploadData = $this->upload->data(); $picture = $uploadData['file_name']; // return $uploadfilename; } else { $error = array('error' => $this->upload->display_errors()); $picture = ''; } } else { $picture = ''; } return $picture ; } function addloadfile() { //echo 'Add new file '; $upfiles = ''; $pono= $this->input->post('PONO'); $igr= $this->input->post('igr'); //print_r($igr); $new_file_name =$_FILES['file']['name']; $new_file_name = str_replace(" ","",$new_file_name); // print_r($new_file_name); $files = $this->inwardgateregister_model->getfies($igr); //print_r($files); $fcount = 0; foreach ($files as $value) { $lastfile = $value->FilePath; if($lastfile == $new_file_name) { //echo 'eqal'; // echo 'cm'.$fcount; $fcount ++; //echo 'cp'.$fcount; } } if($fcount == 0) { //echo 'if'.$fcount.'
'; if(!empty($new_file_name)) { $Picture = $this->adfile(); // print_r($Picture); die; $myfiles =array('PONO'=>$pono,'IGRNO'=>$igr,'FilePath'=>$Picture); $upfiles = $this->inwardgateregister_model->fileupload($myfiles); //print_r($upfiles); } } //echo 'filename'.$upfiles; if( $upfiles > 0){ echo "file updated successfully!"; } else { echo "File name already Exist"; } } function add($pathname) { // echo "add files"; // die(); //echo $pathname; die(); $picture = ''; if(!empty($_FILES[$pathname]['name'])) { $config['upload_path'] = 'uploads/Igrfiles/'; $config['allowed_types'] = '*'; //$config['allowed_types'] = 'jpg|jpeg|png|gif'; $config['file_name'] = str_replace(" ","",$_FILES[$pathname]['name']); //Load upload library and initialize configuration $this->load->library('upload',$config); $this->upload->initialize($config); if($this->upload->do_upload($pathname)) { // echo "uploadif"; $uploadData = $this->upload->data(); $picture = $uploadData['file_name']; } else { $error = array('error' => $this->upload->display_errors()); // $uploadfilename = ''; // print_r($error); // return 0; $picture = ''; } } else { // echo "else"; $picture = ''; } return $picture ; } /** * To Store IGR data into DB */ function edituploadfile() { $bill= $this->input->post('param1'); $oldfile = $this->input->post('param2'); $newfile =$this->input->post('file'); // $new_file_name =$_FILES['file']['name']; $newfile = str_replace(" ","",$newfile); if(!empty($_FILES['file']['name'])) { $Picture = $this->adfile(); }else{ $Picture = $oldfile ; } //echo $Picture;die; $uploadfile = $this->inwardgateregister_model->updatefile($bill,$Picture,$oldfile); // if($uploadfile > 0){ echo "updated successfully!"; // } // else{ // echo "updated successfully!"; // } } function addNewigr() { $PONO = $this->input->post('PONO'); $DeliveryChellanOrInvoiceNo = $this->input->post('InvoiceNo'); $DeliveryChellan = $this->input->post('InvoiceDate'); $DeliveryChellanDate = $this->getDateformat($DeliveryChellan); $Mat_Rcvd_Dt = $this->input->post('MaterialRcvdDate'); $MaterialRcvdDt = $this->getDateformat($Mat_Rcvd_Dt); $VehicleNo = $this->input->post('VehicleNo'); $CourierNo = $this->input->post('CourierNo'); $CreatedBy = $this->session->userdata('userId'); $RowCount = $this->input->post('txtRowCount'); $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createddt = $dt->format('Y-m-d H:i:s'); $IGRStatus = IGR_CREATED; $document = null; $igr = array(); $igr = array('PONO'=>$PONO,'VehicleNo'=>$VehicleNo,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanOrInvoiceNo,'DeliveryChellanDate'=>$DeliveryChellanDate,'MaterialRcvdDate'=>$MaterialRcvdDt,'CourierNo'=>$CourierNo,'IGRStatus'=>$IGRStatus,'CreatedBy'=>$CreatedBy,'CreatedDate' =>$createddt); $igrM = $this->inwardgateregister_model->addigrM($igr); $IGRNO = ''; if(count($igrM)>0) { foreach ($igrM as $key ) { $IGRNO=$key->IGRNO; } } $constant = $this->input->post('hideconstants'); $arr = []; $prefile =array(); for($i=1;$i<=$constant;$i++) { $pathname = 'browseFiles'.$i; if(!empty($_FILES[$pathname]['name'])) { $files = str_replace(" ","",$_FILES[$pathname]['name']); $fcount = 0; foreach ($prefile as $value) { if($value == $files) { $fcount++; } } if($fcount == 0) { $Picture = $this->add($pathname); $arr[] = array($Picture); } $prefile[] = $files; } } if(!empty($arr)) { foreach($arr as $ma){ $index = 0; foreach($ma as $key=>$value){ $index++; if($index == 1){ $filename = $value; } } if(!empty($filename)) { $myfile = array('FilePath'=>$filename,'PONO'=>$PONO,'IGRNO'=>$IGRNO); $this->inwardgateregister_model->fileupload($myfile); } } } $OGRStatus=IGR_CREATED; $check_OGRPO= $this->inwardgateregister_model->update_OGR($PONO,$OGRStatus); $IGRNO = ''; if(count($igrM)>0) { foreach ($igrM as $key ) { $IGRNO=$key->IGRNO; } } $IGRItemStatus = REQITEM_NEW; $TotalPendingQty = ''; for ($i = 1; $i <= $RowCount; $i++) { $MaterialCode = trim($this->input->post('MaterialCode'.$i)); $QuantityAsPerInvoice = trim($this->input->post('txtQuantityAsPerInvoice'.$i)); $OrderedQuantity = trim($this->input->post('OrderedQuantity'.$i)); $ReceivedQty = trim($this->input->post('txtReceivedQuantity'.$i)); $PendingQty = $this->input->post('txtPendingQty'.$i); $TotalPendingQty = $TotalPendingQty + $PendingQty; if(strlen($QuantityAsPerInvoice)>0 && $QuantityAsPerInvoice != '0') { $Remarks = $this->input->post('txtRemarks'.$i); $ItemStatus = ''; if($PendingQty == 0.00 ) { $ItemStatus = IGR_CREATED; } else { $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; } $CreatedBy = $this->session->userdata('userId'); $bankstatus = NO_PAIDIGR; $igrDetails = array('IGRNO'=>$IGRNO,'MaterialCode'=>$MaterialCode,'QuantityAsPerInvoice'=>$QuantityAsPerInvoice,'Remarks'=>$Remarks,'IGRItemStatus'=>$IGRItemStatus,'CreatedBy'=>$CreatedBy,'CreatedDate'=>$createddt,'BankStatus'=>$bankstatus); $igrD = $this->inwardgateregister_model->addigrD($igrDetails); $igrlineno =''; if(!empty($igrD)) { foreach($igrD as $ig) { $igrlineno = $ig->IGRItemNo; } } $itemvalue=''; $SupplierId=''; $polineitemvalue = $this->inwardgateregister_model->getitemvalue($PONO,$MaterialCode); foreach($polineitemvalue as $it) { $itemvalue =$it->Rate; $SupplierId =$it->SupplierID; } $historydetails = array('MaterialCode'=>$MaterialCode,'Transaction_type'=>"Add",'Ref_Type'=>"IGR",'Ref_No'=>$igrlineno,'Quantity'=>$QuantityAsPerInvoice,'CreatedBy'=>$CreatedBy,'CreatedOn'=>$createddt,'SupplierID'=>$SupplierId,'ItemValue'=>$itemvalue); $this->inwardgateregister_model->addmaterialhistory($historydetails); // $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; // $current_qty= array('Current_stock'=>$currentav_qty); // $this->inwardgateregister_model->addmaterialmaster($current_qty,$MaterialCode); $Recqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONO,$MaterialCode); $ReceivedQuantity = 0.00; if(count($Recqty)>0) { foreach ($Recqty as $key ) { $ReceivedQuantity=$key->ReceivedQuantity; } } $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; $POLineItem = array('ReceivedQuantity'=>$totalReceivedqty,'Status'=>$ItemStatus,'UpdateBY'=>$CreatedBy,'UpdatedOn'=>$createddt ); $this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$PONO,$MaterialCode); } } $this->inwardgateregister_model->UpdatePOMaster($PONO,$CreatedBy); if($TotalPendingQty == 0.00){ $Newstatus = array('Status'=>IGR_CREATED); $this->inwardgateregister_model->POLineItemsupdatestatus($PONO,$Newstatus); $this->inwardgateregister_model->pomasterupdatestatus($PONO,$Newstatus); } else{ /*echo 'error' ;*/ } echo ""; } /** *To get igr Datas form ajax */ function ViewIGR() { $IGRNO= $this->input->post('id'); //echo $IGRNO; $data = $this->inwardgateregister_model->viewigr($IGRNO); // print_r($data); echo json_encode($data); } function ViewIGRfile() { $IGRNO= $this->input->post('id'); // echo($IGRNO); $igrfile = $this->inwardgateregister_model->viewIGRFile($IGRNO); $billfile = $this->inwardgateregister_model->ViewIGRfile1($IGRNO); $data = array_merge($igrfile,$billfile); //print_r($data); echo json_encode($data); } /** *To Update igr Datas form ajax */ function UpdateIGR() { $IGRNo = $this->input->post('igr'); $DeliveryChellan = $this->input->post('invdate'); $DeliveryChellanDate = $this->getDateformat($DeliveryChellan); $Mat_Rcvd_Dt = $this->input->post('mrc'); $MaterialRcvdDt = $this->getDateformat($Mat_Rcvd_Dt); $updateby = $this->session->userdata('userId'); $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedon = $dt->format('Y-m-d H:i:s'); $igrarr = array('DeliveryChellanDate'=>$DeliveryChellanDate,'MaterialRcvdDate'=>$MaterialRcvdDt,'UpdateBY'=>$updateby,'UpdatedOn'=>$updatedon); $data = $this->inwardgateregister_model->updateigr($igrarr,$IGRNo); if($data > 0){ echo "Updated Succefully!"; } else{ echo "Not Updated!"; } } function addoutwardgateregister() { $this->load->model('inwardgateregister_model'); $this->global['pageTitle'] = $this->CompanyName.' : Add Outward Gate Register'; //$data['Customer'] = $this->inwardgateregister_model->getCustomer(); $data['Supplier'] = $this->inwardgateregister_model->getSupplier(); $data['storedmaterialcode'] = $this->inwardgateregister_model->getstoredmaterialcode(); $this->loadViews("ogr", $this->global, $data, NULL); } function GetInvoices() { $CustomerId = $this->input->post('customerId'); $data = $this->inwardgateregister_model->getInvoice($CustomerId); echo json_encode($data); } function GetPO() { $supplierId = $this->input->post('supplierId'); $data = $this->inwardgateregister_model->getPO($supplierId); echo json_encode($data); } function getPODetails() { $PONO = $this->input->post('PONO'); $data = $this->inwardgateregister_model->getPODetails($PONO); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function getPOmrir() { $PONO = $this->input->post('PONO'); $data = $this->inwardgateregister_model->getPOmrir($PONO); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function getMRIRDetails() { $MRIRno = $this->input->post('mrirno'); $PONO = $this->input->post('PONO'); $materialcode = $this->input->post('materialcode'); $data = $this->inwardgateregister_model->getPOMRIRDetails($MRIRno,$PONO,$materialcode); echo json_encode($data); } function getMRIR() { $MRIRno = $this->input->post('MRIRNO'); $PONO = $this->input->post('PONO'); $data = $this->inwardgateregister_model->getPOMRIRMaterial($MRIRno,$PONO); echo json_encode($data); } function ViewOgr() { $this->load->model('inwardgateregister_model'); $this->global['pageTitle'] = $this->CompanyName.' : View Outward Gate Register'; $data['OGR_Data'] = $this->inwardgateregister_model->getOGRData(); $this->loadViews("ogrlist", $this->global, $data, NULL); } function EditOGR() { $OGRNO = $_GET['OGRNO']; $MRIRNO = $_GET['MRIRNO']; $this->global['pageTitle'] = $this->CompanyName.' : View Outward Gate Register'; $data['OGR_Data'] = $this->inwardgateregister_model->getOGRDataforedit($OGRNO); $data['OGR_line'] = $this->inwardgateregister_model->getOGRlineDataforedit($OGRNO,$MRIRNO); $this->loadViews("editogr", $this->global, $data, NULL); } function AddOgr() { $type=$this->input->post('type'); $Supplier = $this->input->post('sup'); $Date = $this->input->post('Date'); $vehicle =$this->input->post('Vehicle'); $driver = $this->input->post('drive'); if($type == 1) { $invoice =$this->input->post('invno'); $Otype='Invoice'; $Status ='OGR_COMPLETE'; $ogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver ,'PONO_INV'=>$invoice,'VehicleNo'=>$vehicle,'Status'=>$Status); $addogrmaster= $this->inwardgateregister_model->AddOGR($ogrmaster); $OGRNO = ''; if(count($addogrmaster)>0) { foreach($addogrmaster as $add) { $OGRNO = $add->OGRNO; } } $itemcode =$this->input->post('itemcode'); $Description = $this->input->post('Description'); $invoutwardqty = $this->input->post('invoutwardqty'); $Ogrline= array('OGRNO'=>$OGRNO,'MaterialCode'=>$itemcode,'OutwardQty'=>$invoutwardqty,'Status'=>$Status); $addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline); if((count($addogrmaster)>0)&&(count($addOgrline>0))) { echo "Saved Successfully OGR No is OGR".$OGRNO; } } else if($type == 2) { $pono =$this->input->post('pono'); $MRIRNO = $this->input->post('mrirno'); $Otype='PO'; $row= $this->input->post('rowcount'); $ogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver ,'PONO_INV'=>$pono,'VehicleNo'=>$vehicle,'MRIRNO'=>$MRIRNO); $addogrmaster= $this->inwardgateregister_model->AddOGR($ogrmaster); $OGRNO = ''; if(count($addogrmaster)>0) { foreach($addogrmaster as $add) { $OGRNO = $add->OGRNO; } } for($i=1;$i<=$row;$i++) { $MaterialCode = $this->input->post('materialcode'.$i); $OutwardQty = $this->input->post('outward'.$i); $rejqty = $this->input->post('RejectedQty'.$i); $pendingoutward = $this->input->post('pendingoutward'.$i); $balance_Qty= $rejqty-$OutwardQty; //$balance_Qty = $this->input->post('pendingoutward'.$i); $Outwardtotal = $OutwardQty; $allowed= $this->input->post('allowed'.$i); if($MaterialCode != '' && $OutwardQty !='') { $polqty= $this->inwardgateregister_model->getPOLineItemReceivedQty($pono,$MaterialCode); $ReceivedQuantity = 0.00; if(count($polqty)>0) { foreach ($polqty as $key ) { $ReceivedQuantity=$key->ReceivedQuantity; } } $totalReceivedqty = $ReceivedQuantity - $Outwardtotal; $POMStatus=OGR_CREATED; $POLineItem = array('ReceivedQuantity'=>$totalReceivedqty,'OGR_Status'=>$POMStatus); $this->inwardgateregister_model->UpdatePOLineItem($POLineItem,$pono,$MaterialCode); if($pendingoutward == 0) { $Status = OGR_COMPLETE; } else { $Status = OGR_PARTIAL_COMPLETE; } $Ogrline= array('OGRNO'=>$OGRNO,'MaterialCode'=>$MaterialCode,'OutwardQty'=>$Outwardtotal,'Status'=>$Status,'balance_Qty'=>$balance_Qty); $addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline); //print_r($addOgrline); $ogrlineno=''; $itemvalue=''; $SupplierId=''; $CreatedBy = $this->session->userdata('userId'); $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createddt = $dt->format('Y-m-d H:i:s'); if(count($addogrmaster)>0) { $ogrlinearray= $this->inwardgateregister_model->getlastogrline(); foreach($ogrlinearray as $og) { $ogrlineno = $og->OGRItemNO; } $polineitemvalue = $this->inwardgateregister_model->getitemvalue($pono,$MaterialCode); foreach($polineitemvalue as $it) { $itemvalue =$it->Rate; $SupplierId =$it->SupplierID; } } $historydetails = array('MaterialCode'=>$MaterialCode,'Transaction_type'=>"Reduce",'Ref_Type'=>"OGR",'Ref_No'=>$ogrlineno,'Quantity'=>$Outwardtotal,'CreatedBy'=>$CreatedBy,'CreatedOn'=>$createddt,'ItemValue'=>$itemvalue,'SupplierID'=>$SupplierId); $this->inwardgateregister_model->addmaterialhistory($historydetails); $this->inwardgateregister_model->UpdateOGRMasterOGRStatus($OGRNO); $this->inwardgateregister_model->UpdateMRIRMasterOGRStatus($MRIRNO,$OGRNO); $mrirout= $this->inwardgateregister_model->GetMRIROutQty($MRIRNO,$MaterialCode); $premrirout=0; if(!empty($mrirout)) { foreach($mrirout as $mr) { $premrirout= $mr->Ogr_Out_Qty; } } $totmrirout= $premrirout+$Outwardtotal; $mrirarray=array('Ogr_Out_Qty'=>$totmrirout); $this->inwardgateregister_model->UpdateMRIROUTQty($mrirarray,$MRIRNO,$MaterialCode); $POMasterStatus=array('Status'=>PO_RELEASED); $this->inwardgateregister_model->UpdatePOMasterOGRStatus($pono,$POMasterStatus); } } if((count($addogrmaster)>0)&&(count($addOgrline)>0)) { echo "Saved Successfully OGR No is OGR".$OGRNO; } } else if($type ==3) { $Otype='SERVICE'; $Status ='OGR_COMPLETE'; $ogrmaster = array('OgrType'=>$Otype,'CreatedDate'=>$Date,'Driver'=>$driver,'VehicleNo'=>$vehicle,'Status'=>$Status); $addogrmaster= $this->inwardgateregister_model->AddOGR($ogrmaster); //print_r($addogrmaster); $OGRNO = ''; //echo count($addogrmaster); if(count($addogrmaster)>0) { foreach($addogrmaster as $add) { $OGRNO = $add->OGRNO; } } $material= $this->input->post('material'); $name= $this->input->post('name'); $pooutward= $this->input->post('pooutward'); $destination= $this->input->post('destination'); $Remarks= $this->input->post('Remark'); $Ogrline= array('OGRNO'=>$OGRNO,'MaterialCode'=>$material,'OutwardQty'=>$pooutward,'Destination'=>$destination,'Status'=>$Status,'SupplierID'=>$name,'Remark'=>$Remarks); //print_r($Ogrline); //die(); $addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline); if((count($addogrmaster)>0)&&(count($addOgrline>0))) { echo "Saved Successfully OGR No is OGR".$OGRNO; } } } /** * To load pagenotfound view */ function pageNotFound() { //$this->global['pageTitle'] = 'Resico : 404 - Page Not Found'; $this->global['pageTitle'] = $this->CompanyName.' : 404 - Page Not Found'; $this->loadViews("404", $this->global, NULL, NULL); } } ?>