Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- require_once APPPATH . '/../vendor/autoload.php';
- class Purchase extends CI_Controller
- {
- function __construct() {
- parent::__construct();
- $this->load->model('purchase_model');
- $this->load->model('customer_model');
- $this->load->model('company_setting_model');
- $this->load->model('kurs_model');
- $this->load->model('do_model');
- $this->load->model('signature_model');
- $this->load->model('warehouse_model');
- $this->load->model('supplier_model');
- $this->load->model('log_model');
- $this->load->model('brand_model');
- $this->load->model('ledger_model');
- }
- public function index(){
- $filter = null;
- if(isset($_GET['filter'])) {
- if ($_GET['filter'] != null) {
- $filter = $_GET['filter'];
- }
- }
- // get all purchase record and display list
- $data['data'] = $this->purchase_model->getPurchase($filter);
- $this->load->view('purchase/list',$data);
- }
- /*
- call add purchase view to add purchase
- */
- public function add()
- {
- // load general model where generateAutoNumber method stored
- $this->load->model('general_model');
- $kursdata = $this->company_setting_model->getCurrency();
- $data['product'] = $this->purchase_model->getProduct();
- $data['warehouse'] = $this->purchase_model->getWarehouse();
- $data['supplier'] = $this->purchase_model->getSupplier();
- $data['itemrequest'] = $this->warehouse_model->getItemRequestNo();
- $data['brands'] = $this->brand_model->getBrand();
- // get purchase autonumber from general model
- $data['reference_no'] = $this->general_model->generateAutoNumber('purchase');
- $data['service'] = $this->purchase_model->getService();
- $data['kursdata'] = $kursdata;
- $data['company'] = $this->company_setting_model->getData();
- $data['tax'] = $this->purchase_model->getTax();
- $this->load->view('purchase/add',$data);
- }
- public function delete_po($id){
- $this->db->set('is_delete',1)->where('purchase_id',$id)->update('purchases');
- redirect('purchase');
- }
- public function getItemRequest($supplier_id) {
- $data = $this->warehouse_model->getItemRequestNo($supplier_id);
- echo json_encode($data);
- }
- public function itemRequestData($id){
- $data = $this->purchase_model->getProductAjaxItem($id);
- $data['discount'] = $this->purchase_model->getDiscount();
- echo json_encode($data);
- }
- /*
- this function is used when product add in purchase table
- */
- public function getProductAjax($id){
- $data = $this->purchase_model->getProductAjax($id);
- $data['discount'] = $this->purchase_model->getDiscount();
- echo json_encode($data);
- }
- public function getDetail(){
- $id = $this->input->post('id');
- $data = $this->db->select('pi.purchase_item_id, pi.product_id, pi.quantity, pi.quantityreal, p.code, p.name')
- ->from('purchase_items pi')
- ->join('products p', 'pi.product_id=p.product_id' , 'left')
- ->where('pi.purchase_id', $id)
- ->get()
- ->result();
- $i=0;
- echo '<table class="table table-condensed table-border">';
- echo '<thead>';
- echo '<tr>';
- echo '<th></th>';
- echo '<th>Code</th>';
- echo '<th>Name</th>';
- echo '<th>Qty Remain</th>';
- echo '<th>Qty Shipping</th>';
- echo '</tr>';
- echo '<thead>';
- echo '<tbody>';
- foreach($data as $row){
- echo '<tr>';
- echo '<td><input type="checkbox" name="items_id_for_purchase[' . $i . ']" value="' . $row->purchase_item_id . '"></td>';
- echo '<td>' . $row->code . '</td>';
- echo '<td>' . $row->name . '</td>';
- echo '<td>' . ($row->quantity - $row->quantityreal) . '</td>';
- echo '<td><input type="hidden" name="product_id[' . $i . ']" value="' . $row->product_id . '"><input type="number" class="form-control" style="width:100px" value="0" name="items_qty_for_purchase[' . $i . ']" max="' . ($row->quantity - $row->quantityreal) . '"></td>';
- echo '<tr>';
- $i++;
- }
- echo '</tbody>';
- echo '</table>';
- }
- /*
- This function is used to search product code / name in database
- */
- public function getAutoCodeName($code,$search_option){
- //$code = strtolower($code);
- $p_code = $this->input->post('p_code');
- $p_search_option = $this->input->post('p_search_option');
- $data = $this->purchase_model->getProductCodeName($p_code,$p_search_option);
- if($search_option=="Code"){
- $list = "<ul class='auto-product'>";
- foreach ($data as $val){
- $list .= "<li value=".$val->code.">".$val->code."</li>";
- }
- $list .= "</ul>";
- }
- else{
- $list = "<ul class='auto-product'>";
- foreach ($data as $val){
- $list .= "<li value=".$val->product_id.">".$val->name."</li>";
- }
- $list .= "</ul>";
- }
- echo $list;
- //echo json_encode($data);
- //print_r($list);
- }
- public function getProd($id)
- {
- $data = $this->purchase_model->getPurchaseReceiptItem2($id);
- echo json_encode($data);
- }
- /*
- This function is used to add purchase in database
- */
- public function addBiaya()
- {
- //query
- $ke_slugi = 0;
- $sqlslug= "select count(*) as ke_slug from purchases order by purchase_id desc limit 1";
- $sqlslugi = $this->purchase_model->manualQuery($sqlslug);
- foreach ($sqlslugi->result() as $ke) {
- $ke_slug = $ke->ke_slug;
- }
- $ke_slugi = $ke_slug + 1;
- $dataku = array(
- "purchase_id" => $ke_slugi,
- "user" => $this->session->userdata('user_id')
- );
- $this->purchase_model->insertData("purchases",$dataku);
- //add biaya
- $config['upload_path'] = './assets/doc/';
- $config['allowed_types'] = 'doc|docx|pdf|xls|xlsx';
- $config['overwrite'] = TRUE;
- $this->load->library('upload', $config);
- $this->upload->do_upload('filenya');
- $aa = $this->upload->data();
- $ori = $aa['file_name'];
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya'),
- "keterangan" => $this->input->post('keterangan'),
- "file_upload" => $ori,
- "nominal" => $this->input->post('nominal'),
- "purchase_id" => $ke_slugi
- );
- $this->purchase_model->insertData("purchase_biaya",$data);
- //add biaya
- redirect('purchase/edit/'.$ke_slugi,'refresh');
- }
- public function editBiaya($idku)
- {
- //add biaya
- $config['upload_path'] = './assets/doc/';
- $config['allowed_types'] = 'doc|docx|pdf|xls|xlsx';
- $config['overwrite'] = TRUE;
- $this->load->library('upload', $config);
- $this->upload->do_upload('filenya');
- $aa = $this->upload->data();
- $ori = $aa['file_name'];
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya'),
- "keterangan" => $this->input->post('keterangan'),
- "file_upload" => $ori,
- "nominal" => $this->input->post('nominal'),
- "purchase_id" => $idku
- );
- $this->purchase_model->insertData("purchase_biaya",$data);
- //add biaya
- redirect('purchase/edit/'.$idku,'refresh');
- }
- public function getProdreceived($id)
- {
- $data = $this->do_model->getPurchaseReceiptItem2($id);
- echo json_encode($data);
- }
- public function editReceived()
- {
- $purchaseid2 = $this->input->post('purchase_id');
- $purchaseid = $this->input->post('purchase_order');
- $receivedid = $this->input->post('id_received');
- $data = array(
- "receipt_date" => $this->input->post('received_date'),
- "purchase_id" => $this->input->post('purchase_order'),
- "supplier" => $this->input->post('supplier'),
- "warehouse_staff" => $this->input->post('warehouse_staff')
- );
- $datastock=$this->input->post('purchase_item_id');
- if(!empty($receivedid))
- {
- if($this->purchase_model->editReceipt($receivedid,$data))
- {
- if(!empty($datastock))
- {
- $im=0;
- foreach($datastock as $value)
- {
- $dataman=$this->purchase_model->getPurchaseItemId($value);
- foreach ($dataman as $valueman)
- {
- $data2 = array(
- "quantityreal" => $valueman->quantity
- );
- }
- $this->purchase_model->editPurchaseItemId($value,$data2);
- $im++;
- }
- }
- $this->received($purchaseid2);
- }
- else
- {
- $this->received($purchaseid2);
- }
- }
- else if(empty($receivedid))
- {
- if($this->purchase_model->addModelReceipt($data))
- {
- if(!empty($datastock))
- {
- $im=0;
- foreach($datastock as $value)
- {
- $dataman=$this->purchase_model->getPurchaseItemId($value);
- foreach ($dataman as $valueman)
- {
- $data2 = array(
- "quantityreal" => $valueman->quantity
- );
- }
- $this->purchase_model->editPurchaseItemId($value,$data2);
- $im++;
- }
- }
- $this->received($purchaseid2);
- }
- else
- {
- $this->received($purchaseid2);
- }
- }
- else
- {
- $this->received($purchaseid2);
- }
- }
- /*
- This function is used to add purchase in database
- */
- public function addPurchase()
- {
- $this->form_validation->set_rules('date','Date','trim|required');
- $this->form_validation->set_rules('reference_no','Reference No','trim|required');
- $submit = $this->input->post('submit');
- if ($submit == "Publish") {
- $status = 0;
- } else {
- $status = 6;
- }
- if($this->form_validation->run()==false)
- {
- $this->add();
- }
- else
- {
- $warehouse_id = $this->input->post('warehouse');
- $data = array(
- "reference_no" => $this->input->post('reference_no'),
- "date" => $this->input->post('date'),
- "podate" => $this->input->post('po_date'),
- "supplier_id" => $this->input->post('supplier'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "taxdesc" => $this->input->post('tax'),
- "kurs_id" => $this->input->post('kursdata'),
- "refer_no" => $this->input->post('refer_no'),
- "total" => $this->input->post('grand_total'),
- "discount_value"=> $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "pterm" => $this->input->post('paymenterms'),
- "note" => $this->input->post('note'),
- "user" => $this->session->userdata('user_id'),
- "user_name" => $this->session->userdata('identity'),
- "diskon" => $this->input->post('diskon_text'),
- "diskonpersen" => $this->input->post('diskonpersen_text'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "dateestimate" => $this->input->post('dateestimate'),
- "shipping_address" => $this->input->post('shipping_address'),
- "billing_address" => $this->input->post('billing_address'),
- "status" => $status
- );
- $invoice = array(
- "invoice_no" => $this->purchase_model->generateInvoiceNo(),
- "receipt_amount" => $this->input->post('grand_total'),
- "receipt_voucher_date" => date('Y-m-d')
- );
- // ================ ledger =================
- $am = $this->db->get('account_mapping')->row();
- $data2 = array(
- 'ledger_number' => 'PR-'.rand(),
- 'ledger_date' => $this->input->post('date'),
- );
- if($idr = $this->ledger_model->saveledger($data2)){
- $id_ledger = $idr;
- $account_id = $am->pembelian_cogs;
- $description = 'Pembelian COGS';
- $debit = $this->input->post('grand_total');
- $credit = $this->input->post('grand_total');
- $datas = array();
- $index = 0;
- // foreach($account_id as $dataid){
- array_push($datas,array(
- 'account_id'=>$am->pajak_pembelian,
- 'id_ledger'=>$idr,
- 'description'=>'PPN Masukan',
- 'debit'=>$this->input->post('total_tax'),
- // 'credit'=>$credit[$index],
- ));
- $this->ledger_model->save_batch($datas);
- $datas = [];
- array_push($datas,array(
- 'account_id'=>$am->pajak_pembelian,
- 'id_ledger'=>$idr,
- 'description'=>'Beban Pokok Pendapatan',
- 'debit'=>$this->input->post('grand_total'),
- // 'credit'=>$credit[$index],
- ));
- $this->ledger_model->save_batch($datas);
- $datas = [];
- array_push($datas,array(
- 'account_id'=>$am->pembelian_cogs,
- 'id_ledger'=>$idr,
- 'description'=>'Hutang Usaha',
- 'credit'=>$this->input->post('grand_total'),
- // 'credit'=>$credit[$index],
- ));
- $this->ledger_model->save_batch($datas);
- $datas = [];
- $index++;
- // }
- }
- if($purchase_id = $this->purchase_model->addModel2($data,$invoice))
- {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $purchase_id,
- 'message' => 'Purchase Inserted'
- );
- $this->log_model->insert_log($log_data);
- $jumlahtermin= $this->input->post('terminnumber');
- if(!empty($jumlahtermin))
- {
- $termins = $this->input->post('terminvalue');
- $due_dates = $this->input->post('due_date');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- if(!empty($termins))
- {
- $im=0;
- foreach($termins as $quan)
- {
- $value=$this->input->post('grand_total');
- $nominal=($value*$quan)/100;
- $nominal = number_format((float)$nominal, 2, '.', '');
- $due_date = $due_dates[$im];
- if(!empty($tanggaltermins[$im]))
- {
- $datetermin=$tanggaltermins[$im];
- }
- else
- {
- $datetermin=date('Y-m-d');
- }
- $datatermin = array(
- "purchase_id" => $purchase_id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin,
- "due_date" => $due_date
- );
- // echo '<pre>' . var_export($datatermin, true) . '</pre>';
- // die;
- $this->purchase_model->addTerminModel($datatermin);
- $im++;
- }
- }
- }
- $js_data = json_decode($this->input->post('table_data'));
- if(!empty($js_data))
- {
- foreach ($js_data as $key => $value)
- {
- if($value!=null || !empty($value->product_id))
- {
- $product_id = $value->product_id;
- $quantity = $value->quantity;
- $data = array(
- "product_id" => $value->product_id,
- "quantity" => $value->quantity,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "cost" => $value->cost,
- "price" => $value->price,
- "desc" => $value->desc,
- "purchase_id" => $purchase_id
- );
- $warehouse_data = array(
- "product_id" => $value->product_id,
- "warehouse_id" => 0,
- "quantity" => $value->quantity
- );
- $this->purchase_model->addProductInWarehouse($product_id,$quantity,$warehouse_id,$warehouse_data);
- $this->db->insert('purchase_items', $data);
- }
- }
- }
- $config = array();
- $config['upload_path'] = './assets/doc/';
- $config['allowed_types'] = 'doc|xls|xlsx|docx|pdf|DOC|XLS|XLSX|DOCX|PDF';
- $config['max_size'] = '0';
- $config['overwrite'] = FALSE;
- $config['encrypt_name'] = TRUE;
- $this->load->library('upload');
- $count = count($this->input->post('jenis_biaya'));
- $files = $_FILES;
- for($i=0; $i< $count; $i++)
- {
- if($_FILES['file']['name'][$i]) {
- $_FILES['file'.$i]['name']= $files['file']['name'][$i];
- $_FILES['file'.$i]['type']= $files['file']['type'][$i];
- $_FILES['file'.$i]['tmp_name']= $files['file']['tmp_name'][$i];
- $_FILES['file'.$i]['error']= $files['file']['error'][$i];
- $_FILES['file'.$i]['size']= $files['file']['size'][$i];
- $this->upload->initialize($config);
- if ($this->upload->do_upload('file'.$i)) {
- $a = $this->upload->data();
- $filename = $a['file_name'];
- } else {
- $filename = '';
- }
- }
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya')[$i],
- "keterangan" => $this->input->post('keterangan')[$i],
- "pdf" => $this->input->post('pdf')[$i] ?: 0,
- "file_upload" => $filename,
- "nominal" => $this->input->post('nominal')[$i],
- "purchase_id" => $purchase_id
- );
- $this->db->insert('purchase_biaya', $data);
- }
- redirect('purchase/view/' . $purchase_id);
- }
- else
- {
- $this->add();
- }
- }
- }
- public function deleteBiaya($id){
- $data = $this->db->select('*')->from('purchase_biaya')->where('id', $id)->get()->result()[0]->file_upload;
- unlink(FCPATH . '/assets/doc/' . $data);
- $this->db->where('id', $id);
- $this->db->delete('purchase_biaya');
- }
- public function edit($id)
- {
- $data['biaya'] = $this->purchase_model->getBiaya($id);
- $data['purchase_id'] = $id;
- $kursdata = $this->company_setting_model->getCurrency();
- // if(!$sock= @fsockopen("www.google.com", 80))
- // {
- // }
- // else
- // {
- // foreach($kursdata as $kursd)
- // {
- // $currencyValue2 = $this->currencyConverter2($kursd->kurs,"IDR");
- // $data2 = array(
- // "kurs" => $kursd->kurs,
- // "nominal" => $currencyValue2
- // );
- // $this->kurs_model->editModel($data2,$kursd->kurs_id);
- // }
- // }
- $data['brands'] = $this->brand_model->getBrand();
- $data['product'] = $this->purchase_model->getProduct();
- $data['supplier'] = $this->purchase_model->getSupplier();
- $data['data'] = $this->purchase_model->getRecord($id);
- $data['discount'] = $this->purchase_model->getDiscount();
- $data['tax'] = $this->purchase_model->getTax();
- $data['kursdata'] = $kursdata;
- $data['company'] = $this->company_setting_model->getData();
- $data['termin'] = $this->purchase_model->getTerminId($data['data'][0]->purchase_id);
- foreach ($data['data'] as $key)
- {
- $data['items'] = $this->purchase_model->getPurchaseItems($id);
- }
- $this->load->view('purchase/edit',$data);
- }
- public function revisi($id)
- {
- $data['biaya'] = $this->purchase_model->getBiaya($id);
- $data['purchase_id'] = $id;
- $kursdata = $this->company_setting_model->getCurrency();
- // if(!$sock= @fsockopen("www.google.com", 80))
- // {
- // }
- // else
- // {
- // foreach($kursdata as $kursd)
- // {
- // $currencyValue2 = $this->currencyConverter2($kursd->kurs,"IDR");
- // $data2 = array(
- // "kurs" => $kursd->kurs,
- // "nominal" => $currencyValue2
- // );
- // $this->kurs_model->editModel($data2,$kursd->kurs_id);
- // }
- // }
- $data['brands'] = $this->brand_model->getBrand();
- $data['product'] = $this->purchase_model->getProduct();
- $data['supplier'] = $this->purchase_model->getSupplier();
- $data['data'] = $this->purchase_model->getRecord($id);
- $data['discount'] = $this->purchase_model->getDiscount();
- $data['tax'] = $this->purchase_model->getTax();
- $data['kursdata'] = $kursdata;
- $data['company'] = $this->company_setting_model->getData();
- $data['termin'] = $this->purchase_model->getTerminId($data['data'][0]->purchase_id);
- foreach ($data['data'] as $key)
- {
- $data['items'] = $this->purchase_model->getPurchaseItems($id);
- }
- $this->load->view('purchase/revisi',$data);
- }
- /*
- This function is used to delete discount record in databse
- */
- public function delete($id){
- if($this->purchase_model->deleteModel($id)){
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Purchase Deleted'
- );
- $this->log_model->insert_log($log_data);
- redirect('purchase','refresh');
- }
- else{
- redirect('purchase','refresh');
- }
- }
- /*
- This function is to edit purchase record in database
- */
- public function editVoid()
- {
- $id = $this->input->post('id');
- $voiddesc = $this->input->post('voiddesc');
- $data = array(
- "voiddesc" => $voiddesc,
- "status" => 4
- );
- if($this->purchase_model->editModel($id,$data))
- {
- redirect('purchase');
- }
- else
- {
- redirect('purchase');
- }
- }
- public function editClosepo()
- {
- $id = $this->input->post('id');
- $closepo = $this->input->post('closepo');
- $reference_no = $this->input->post('reference_no');
- $data = array(
- "reference_no" => $reference_no,
- "closepo" => $closepo,
- "status" => 6
- );
- if($id = $this->purchase_model->editModel($id,$data))
- {
- $index = 0;
- $data1 = array(
- "ledger_number" => $this->input->post('reference_no'),
- "ledger_id" => $this->input->post('id')
- );
- $index++;
- $this->purchase_model->addModelledger($data1);
- redirect('purchase');
- }
- else
- {
- redirect('purchase');
- }
- }
- public function editShipping()
- {
- $id = $this->input->post('id');
- $shipstatus = $this->input->post('shipstatus');
- $shipawb = $this->input->post('shipawb');
- $shipdate = $this->input->post('shipdate');
- $shiptrackno = $this->input->post('shiptrackno');
- $shipcourier = $this->input->post('shipcourier');
- $shipfreight = $this->input->post('shipfreight');
- $shipfile = $this->input->post('shipfile');
- $shipto = $this->input->post('shipto');
- if($_FILES["shipfile"]["name"] == null)
- {
- $url = $this->input->post('hidden_image');
- }
- else
- {
- $type = explode('.',$_FILES["shipfile"]["name"]);
- $type = $type[count($type)-1];
- $url = "./assets/shipping/".uniqid(rand()).'.'.$type;
- if(in_array($type,array("jpg","jpeg","gif","png","doc","docx","xls","xlsx")))
- {
- if(is_uploaded_file($_FILES["shipfile"]["tmp_name"]))
- {
- if(move_uploaded_file($_FILES["shipfile"]["tmp_name"],$url))
- {
- $url = base_url().''.$url;
- }
- }
- }
- }
- $data = array(
- "shipstatus" => $shipstatus,
- "shipawb" => $shipawb,
- "shipdate" => $shipdate,
- "shiptrackno" => $shiptrackno,
- "shipcourier" => $shipcourier,
- "freight" => $shipfreight,
- "shipfile" => $url,
- "shipto" => $shipto,
- "purchase_id" => $id
- );
- if($idm = $this->purchase_model->addModelShipping($data))
- {
- if ($shipstatus == 'Partial') {
- foreach($_POST['items_id_for_purchase'] as $i => $si_id){
- $product_qty = $_POST['items_qty_for_purchase'][$i];
- $qty = $_POST['items_qty_for_purchase'][$i];
- $idp = $_POST['product_id'][$i];
- $idi = $_POST['items_id_for_purchase'][$i];
- $this->db->query("UPDATE purchase_items SET quantityreal=IFNULL(quantityreal, 0 ) + $qty WHERE purchase_item_id=$idi");
- $data = array(
- 'purchase_id' => $id,
- 'product_id' => $idp,
- 'purchase_shipping_id' => $idm,
- 'quantity' => $qty,
- 'status' => 2
- );
- $this->db->insert('purchase_shipping_items', $data);
- }
- } else {
- $querys = $this->db->select('*')->from('purchase_items')->where('purchase_id', $id)->get()->result();
- foreach ($querys as $row) {
- $quantityreal = ($row->quantityreal == NULL) ? 0 : $row->quantityreal;
- $ids = $row->purchase_item_id;
- $qty = ($row->quantity - $quantityreal);
- $idp = $row->product_id;
- if ($row->quantityreal == NULL) {
- $quantityreal = 0;
- } else {
- $quantityreal = $row->quantityreal;
- }
- $this->db->query("UPDATE purchase_items SET quantityreal=$quantityreal + $qty WHERE purchase_item_id=$ids");
- $data = array(
- 'purchase_id' => $id,
- 'product_id' => $idp,
- 'purchase_shipping_id' => $idm,
- 'quantity' => $qty,
- 'status' => 2
- );
- $this->db->insert('purchase_shipping_items', $data);
- }
- }
- $data2 = array(
- "status" => 2
- );
- if($this->purchase_model->editModelShipping($id,$data2))
- {
- redirect('purchase');
- }
- else
- {
- redirect('purchase');
- }
- }
- else
- {
- redirect('purchase');
- }
- }
- public function editClerance()
- {
- $id = $this->input->post('id');
- $cleranceawb = $this->input->post('cleranceawb');
- $clerancedate = $this->input->post('clerancedate');
- $clerancetrackno = $this->input->post('clerancetrackno');
- $clerancecourier = $this->input->post('clerancecourier');
- $clerancefreight = $this->input->post('clerancefreight');
- $clerancefile = $this->input->post('clerancefile');
- $clerancepib = $this->input->post('clerancepib');
- $dutytax = $this->input->post('dutytax');
- if($_FILES["clerancefile"]["name"] == null)
- {
- $url = 'null';
- $type = "null";
- }
- else
- {
- $type = explode('.',$_FILES["clerancefile"]["name"]);
- $type = $type[count($type)-1];
- $url = "./assets/clerance/".uniqid(rand()).'.'.$type;
- if(in_array($type,array("jpg","jpeg","gif","png","doc","docx","xls","xlsx")))
- {
- if(is_uploaded_file($_FILES["clerancefile"]["tmp_name"]))
- {
- if(move_uploaded_file($_FILES["clerancefile"]["tmp_name"],$url))
- {
- $url = base_url().''.$url;
- }
- }
- }
- }
- $data = array(
- "cleranceawb" => $cleranceawb,
- "clerancedate" => $clerancedate,
- "clerancetrackno" => $clerancetrackno,
- "clerancecourier" => $clerancecourier,
- "clerancefreight" => $clerancefreight,
- "clerancefile" => $url,
- "clerancepib" => $clerancepib,
- "dutytax" => $dutytax,
- "purchase_id" => $id
- );
- if($idm=$this->purchase_model->addModelClearence($data))
- {
- $data2 = array(
- "status" => 3
- );
- if($this->purchase_model->editModelClearence($id,$data2))
- {
- redirect('purchase');
- }
- else
- {
- redirect('purchase');
- }
- }
- else
- {
- redirect('purchase');
- }
- }
- public function editPurchase()
- {
- $id = $this->input->post('purchase_id');
- $submit = $this->input->post('submit');
- if ($submit == "Update") {
- $status = 0;
- } else {
- $status = 6;
- }
- $this->form_validation->set_rules('date','Date','trim|required');
- $this->form_validation->set_rules('reference_no','Reference No','trim|required');
- if($this->form_validation->run()==false)
- {
- $this->add();
- }
- else
- {
- $data = array(
- "reference_no" => $this->input->post('reference_no'),
- "date" => $this->input->post('date'),
- "podate" => $this->input->post('po_date'),
- "supplier_id" => $this->input->post('supplier'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "taxdesc" => $this->input->post('tax'),
- "kurs_id" => $this->input->post('kursdata'),
- "refer_no" => $this->input->post('refer_no'),
- "total" => $this->input->post('grand_total'),
- "discount_value"=> $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "pterm" => $this->input->post('paymenterms'),
- "note" => $this->input->post('note'),
- "user" => $this->session->userdata('user_id'),
- "user_name" => $this->session->userdata('identity'),
- "diskon" => $this->input->post('diskon_text'),
- "diskonpersen" => $this->input->post('diskonpersen_text'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "dateestimate" => $this->input->post('dateestimate'),
- "shipping_address" => $this->input->post('shipping_address'),
- "billing_address" => $this->input->post('billing_address'),
- "status" => $status
- );
- $invoice = array(
- "invoice_no" => $this->purchase_model->generateInvoiceNo(),
- "receipt_amount" => $this->input->post('grand_total'),
- "receipt_voucher_date" => date('Y-m-d')
- );
- if($this->purchase_model->editModel($id,$data))
- {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Purchase Updated'
- );
- $this->log_model->insert_log($log_data);
- $jumlahtermin = $this->input->post('terminnumber');
- if(!empty($jumlahtermin))
- {
- $this->db->where('purchase_id', $id);
- $this->db->delete('purchase_termin');
- $termins = $this->input->post('terminvalue');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- if(!empty($termins))
- {
- $im=0;
- foreach($termins as $quan)
- {
- $value=$this->input->post('grand_total');
- $nominal=($value*$quan)/100;
- $nominal = number_format((float)$nominal, 2, '.', '');
- if(!empty($tanggaltermins[$im]))
- {
- $datetermin=$tanggaltermins[$im];
- }
- else
- {
- $datetermin=date('Y-m-d');
- }
- $datatermin = array(
- "purchase_id" => $id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin
- );
- $this->purchase_model->addTerminModel($datatermin);
- $im++;
- }
- }
- }
- $this->db->where('purchase_id', $id);
- $this->db->delete('purchase_items');
- $js_data = json_decode($this->input->post('table_data'));
- if(!empty($js_data))
- {
- foreach ($js_data as $key => $value)
- {
- if($value!=null && !empty($value->product_id))
- {
- $product_id = $value->product_id;
- $quantity = $value->quantity;
- $data = array(
- "product_id" => $value->product_id,
- "quantity" => $value->quantity,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "cost" => @$value->cost,
- "price" => $value->price,
- "desc" => $value->desc,
- "purchase_id" => $id
- );
- $warehouse_data = array(
- "product_id" => $value->product_id,
- "warehouse_id" => 0,
- "quantity" => $value->quantity
- );
- $this->db->insert('purchase_items', $data);
- }
- }
- }
- $config = array();
- $config['upload_path'] = './assets/doc/';
- $config['allowed_types'] = 'doc|xls|xlsx|docx|pdf|DOC|XLS|XLSX|DOCX|PDF';
- $config['max_size'] = '0';
- $config['overwrite'] = FALSE;
- $config['encrypt_name'] = TRUE;
- $this->load->library('upload');
- $count = count($this->input->post('jenis_biaya'));
- // $count = 0;
- $files = $_FILES;
- for($i=0; $i< $count; $i++)
- {
- if ($this->input->post('biaya_id')[$i] != NULL || !empty($this->input->post('biaya_id')[$i])) {
- if($_FILES['file']['name'][$i]) {
- $_FILES['file'.$i]['name']= $files['file']['name'][$i];
- $_FILES['file'.$i]['type']= $files['file']['type'][$i];
- $_FILES['file'.$i]['tmp_name']= $files['file']['tmp_name'][$i];
- $_FILES['file'.$i]['error']= $files['file']['error'][$i];
- $_FILES['file'.$i]['size']= $files['file']['size'][$i];
- $this->upload->initialize($config);
- $data = $this->db->select('*')->from('purchase_biaya')->where('id', $this->input->post('biaya_id')[$i])->get()->result()[0]->file_upload;
- unlink(FCPATH . '/assets/doc/' . $data);
- if ($this->upload->do_upload('file'.$i)) {
- $a = $this->upload->data();
- $filename = $a['file_name'];
- }
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya')[$i],
- "keterangan" => $this->input->post('keterangan')[$i],
- "pdf" => $this->input->post('pdf')[$i] ?: 0,
- "file_upload" => $filename,
- "nominal" => $this->input->post('nominal')[$i],
- );
- $this->db->where('id', $this->input->post('biaya_id')[$i]);
- $this->db->update('purchase_biaya', $data);
- } else {
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya')[$i],
- "keterangan" => $this->input->post('keterangan')[$i],
- "pdf" => $this->input->post('pdf')[$i] ?: 0,
- "nominal" => $this->input->post('nominal')[$i],
- );
- $this->db->where('id', $this->input->post('biaya_id')[$i]);
- $this->db->update('purchase_biaya', $data);
- }
- } else {
- if($_FILES['file']['name'][$i]) {
- $_FILES['file'.$i]['name']= $files['file']['name'][$i];
- $_FILES['file'.$i]['type']= $files['file']['type'][$i];
- $_FILES['file'.$i]['tmp_name']= $files['file']['tmp_name'][$i];
- $_FILES['file'.$i]['error']= $files['file']['error'][$i];
- $_FILES['file'.$i]['size']= $files['file']['size'][$i];
- $this->upload->initialize($config);
- if ($this->upload->do_upload('file'.$i)) {
- $a = $this->upload->data();
- $filename = $a['file_name'];
- }
- } else {
- $filename = '';
- }
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya')[$i],
- "keterangan" => $this->input->post('keterangan')[$i],
- "pdf" => $this->input->post('pdf')[$i] ?: 0,
- "file_upload" => $filename,
- "nominal" => $this->input->post('nominal')[$i],
- "purchase_id" => $id
- );
- $this->db->insert('purchase_biaya', $data);
- }
- }
- redirect('purchase/view/' . $id);
- }
- }
- }
- public function revisiPurchase()
- {
- $id = $this->input->post('purchase_id');
- $submit = $this->input->post('submit');
- if ($submit == "Publish") {
- $status = 0;
- } else {
- $status = 4;
- }
- $this->form_validation->set_rules('date','Date','trim|required');
- $this->form_validation->set_rules('reference_no','Reference No','trim|required');
- if($this->form_validation->run()==false)
- {
- $this->add();
- }
- else
- {
- $warehouse_id = $this->input->post('warehouse');
- $data = array(
- "reference_no" => $this->input->post('reference_no'),
- "norevisi" => $this->input->post('norevisi'),
- "date" => $this->input->post('date'),
- "podate" => $this->input->post('po_date'),
- "supplier_id" => $this->input->post('supplier'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "taxdesc" => $this->input->post('tax'),
- "kurs_id" => $this->input->post('kursdata'),
- "refer_no" => $this->input->post('refer_no'),
- "total" => $this->input->post('grand_total'),
- "discount_value"=> $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "pterm" => $this->input->post('paymenterms'),
- "note" => $this->input->post('note'),
- "user" => $this->session->userdata('user_id'),
- "user_name" => $this->session->userdata('identity'),
- "diskon" => $this->input->post('diskon_text'),
- "diskonpersen" => $this->input->post('diskonpersen_text'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "dateestimate" => $this->input->post('dateestimate'),
- "shipping_address" => $this->input->post('shipping_address'),
- "billing_address" => $this->input->post('billing_address'),
- "status" => $status
- );
- $invoice = array(
- "invoice_no" => $this->purchase_model->generateInvoiceNo(),
- "receipt_amount" => $this->input->post('grand_total'),
- "receipt_voucher_date" => date('Y-m-d')
- );
- if($purchase_id = $this->purchase_model->addModel2($data,$invoice))
- {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $purchase_id,
- 'message' => 'Purchase Inserted'
- );
- $this->log_model->insert_log($log_data);
- $jumlahtermin= $this->input->post('terminnumber');
- if(!empty($jumlahtermin))
- {
- $termins = $this->input->post('terminvalue');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- if(!empty($termins))
- {
- $im=0;
- foreach($termins as $quan)
- {
- $value=$this->input->post('grand_total');
- $nominal=($value*$quan)/100;
- $nominal = number_format((float)$nominal, 2, '.', '');
- if(!empty($tanggaltermins[$im]))
- {
- $datetermin=$tanggaltermins[$im];
- }
- else
- {
- $datetermin=date('Y-m-d');
- }
- $datatermin = array(
- "purchase_id" => $purchase_id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin
- );
- $this->purchase_model->addTerminModel($datatermin);
- $im++;
- }
- }
- }
- $js_data = json_decode($this->input->post('table_data'));
- if(!empty($js_data))
- {
- foreach ($js_data as $key => $value)
- {
- if($value!=null || !empty($value->product_id))
- {
- $product_id = $value->product_id;
- $quantity = $value->quantity;
- $data = array(
- "product_id" => $value->product_id,
- "quantity" => $value->quantity,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "cost" => $value->cost,
- "price" => $value->price,
- "desc" => $value->desc,
- "purchase_id" => $purchase_id
- );
- $warehouse_data = array(
- "product_id" => $value->product_id,
- "warehouse_id" => 0,
- "quantity" => $value->quantity
- );
- $this->purchase_model->addProductInWarehouse($product_id,$quantity,$warehouse_id,$warehouse_data);
- $this->db->insert('purchase_items', $data);
- }
- }
- }
- $config = array();
- $config['upload_path'] = './assets/doc/';
- $config['allowed_types'] = 'doc|xls|xlsx|docx|pdf|DOC|XLS|XLSX|DOCX|PDF';
- $config['max_size'] = '0';
- $config['overwrite'] = FALSE;
- $config['encrypt_name'] = TRUE;
- $this->load->library('upload');
- $count = count($this->input->post('jenis_biaya'));
- $files = $_FILES;
- for($i=0; $i< $count; $i++)
- {
- if($_FILES['file']['name'][$i]) {
- $_FILES['file'.$i]['name']= $files['file']['name'][$i];
- $_FILES['file'.$i]['type']= $files['file']['type'][$i];
- $_FILES['file'.$i]['tmp_name']= $files['file']['tmp_name'][$i];
- $_FILES['file'.$i]['error']= $files['file']['error'][$i];
- $_FILES['file'.$i]['size']= $files['file']['size'][$i];
- $this->upload->initialize($config);
- if ($this->upload->do_upload('file'.$i)) {
- $a = $this->upload->data();
- $filename = $a['file_name'];
- } else {
- $filename = '';
- }
- }
- $data = array(
- "jenis_biaya" => $this->input->post('jenis_biaya')[$i],
- "keterangan" => $this->input->post('keterangan')[$i],
- "pdf" => $this->input->post('pdf')[$i] ?: 0,
- "file_upload" => $filename,
- "nominal" => $this->input->post('nominal')[$i],
- "purchase_id" => $purchase_id
- );
- $this->db->insert('purchase_biaya', $data);
- }
- $dataman = array(
- "status_rev" => 2
- );
- $this->db->where('id', $id);
- $this->db->update('purchases', $data);
- redirect('purchase/view/' . $purchase_id);
- }
- }
- }
- /*
- view purchase details
- */
- public function view($id)
- {
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['purchasetermins'] = $this->purchase_model->getTerminId($id);
- $data['items'] = $this->purchase_model->getItems($id);
- // print_r(var_dump($this->db->last_query()));
- $data['company'] = $this->purchase_model->getCompany();
- $data['symbol'] = $this->db->select('*')->from("currency")->where("kurs_id", $data['data'][0]->kurs_id)->get()->result()[0]->symbol;
- $this->load->view('purchase/view',$data);
- }
- public function ditolak($id)
- {
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['purchasetermins'] = $this->purchase_model->getTerminId($id);
- $data['items'] = $this->purchase_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $this->load->view('purchase/ditolak',$data);
- }
- public function disetujui($id)
- {
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['purchasetermins'] = $this->purchase_model->getTerminId($id);
- $data['items'] = $this->purchase_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $this->load->view('purchase/disetujui',$data);
- }
- public function changeSetujui() {
- $id = $this->input->post('purchase_id');
- $data = array(
- 'status' => 2,
- 'disetujuidesc' => $this->input->post('disetujui')
- );
- $update = $this->db->where('purchase_id', $id)->update('purchases', $data);
- if ($update) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Change Ditolak Purchase Updated'
- );
- $this->log_model->insert_log($log_data);
- $this->session->set_flashdata('success', 'Purchase Order Has Been Approved.');
- redirect('purchase', 'refresh');
- } else {
- $this->session->set_flashdata('fail', 'Purchase Order Can\'t Been Approved.');
- redirect('purchase', 'refresh');
- }
- }
- public function changeTolak() {
- $id = $this->input->post('purchase_id');
- $data = array(
- 'status' => 3,
- 'ditolakdesc' => $this->input->post('ditolak')
- );
- $update = $this->db->where('purchase_id', $id)->update('purchases', $data);
- if ($update) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Change Ditolak Purchase Updated'
- );
- $this->log_model->insert_log($log_data);
- $this->session->set_flashdata('success', 'Purchase Order Has Been Rejected.');
- redirect('purchase', 'refresh');
- } else {
- $this->session->set_flashdata('fail', 'Purchase Order Can\'t Reject.');
- redirect('purchase', 'refresh');
- }
- }
- /*
- generate pdf
- */
- public function pdf($id) {
- ob_start();
- $html = ob_get_clean();
- $html = utf8_encode($html);
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['items'] = $this->purchase_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['company_setting'] = $this->company_setting_model->getData();
- $data['signature'] = $this->signature_model->getActiveSignature();
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->supplier_id);
- $data['supplier'] = $this->supplier_model->getRecord($data['data'][0]->supplier_id);
- $data['biaya'] = $this->purchase_model->getBiayaDoc($id);
- $data['symbol'] = $this->db->select('*')->from("currency")->where("kurs_id", $data['data'][0]->kurs_id)->get()->result()[0]->symbol;
- $t = 0;
- foreach ($data['items'] as $value) { $t += ($value->price * $value->quantity); }
- foreach ($data['biaya'] as $value) { $t += $value->nominal; }
- $r = $t - $data['data'][0]->discount_value + $data['data'][0]->tax_value;
- if ($r > $t) {
- $font = $r;
- } else {
- $font = $t;
- }
- if(strlen($font) <= 9) {
- $data['style'] = 'style="font-size: 9pt"';
- $data['style2'] = 'style="font-size: 8pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) == 10) {
- $data['style'] = 'style="font-size: 8pt"';
- $data['style2'] = 'style="font-size: 7pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) >= 11) {
- $data['style'] = 'style="font-size: 7pt"';
- $data['style2'] = 'style="font-size: 6pt; font-style: italic; font-weight: bold;"';
- }
- $html = $this->load->view('purchase/pdf', $data, true);
- $logo = base_url(header_logo('logo'));
- $width = header_logo('width');
- $height = header_logo('height');
- $mpdf = new \Mpdf\Mpdf();
- // $mpdf->SetHTMLHeader('<table style=" vertical-align: bottom; font-family: serif; font-size: 9pt;" width="100%">
- // <tr>
- // <td width="40%" valign="top"><img src="'. $logo .'" width="'. $width .'" height="'. $height .'"></td>
- // <td style="text-align: right;" width="60%">
- // '.header_doc() . '
- // </td>
- // </tr>
- // </table>');
- $mpdf->AddPageByArray([
- 'margin-left' => 5,
- 'margin-right' => 5,
- // 'margin-top' => 0,
- // 'margin-bottom' => 0,
- ]);
- if ($data['data'][0]->status == 4) {
- $status = 'Draft';
- $mpdf->SetWatermarkText($status);
- $mpdf->showWatermarkText = true;
- } else {
- $mpdf->SetWatermarkImage(base_url('/assets/images/logo-glodisaaa.jpg'));
- //disuruh hapus watermark
- $mpdf->showWatermarkImage = true;
- }
- $mpdf->allow_charset_conversion = true;
- $mpdf->charset_in = 'UTF-8';
- $mpdf->WriteHTML($html);
- $mpdf->Output($data['data'][0]->reference_no . 'pdf', 'I');
- }
- public function word($id) {
- ob_start();
- $html = ob_get_clean();
- $html = utf8_encode($html);
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['items'] = $this->purchase_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['company_setting'] = $this->company_setting_model->getData();
- $data['signature'] = $this->signature_model->getActiveSignature();
- $data['supplier'] = $this->supplier_model->getRecord($data['data'][0]->supplier_id);
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->supplier_id);
- $data['symbol'] = $this->db->select('*')->from("currency")->where("kurs_id", $data['data'][0]->kurs_id)->get()->result()[0]->symbol;
- $data['biaya'] = $this->purchase_model->getBiayaDoc($id);
- $t = 0;
- foreach ($data['items'] as $value) { $t += ($value->price * $value->quantity); }
- foreach ($data['biaya'] as $value) { $t += $value->nominal; }
- $r = $t - $data['data'][0]->discount_value + $data['data'][0]->tax_value;
- if ($r > $t) {
- $font = $r;
- } else {
- $font = $t;
- }
- if(strlen($font) <= 9) {
- $data['style'] = 'style="font-size: 9pt"';
- $data['style2'] = 'style="font-size: 8pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) == 10) {
- $data['style'] = 'style="font-size: 8pt"';
- $data['style2'] = 'style="font-size: 7pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) >= 11) {
- $data['style'] = 'style="font-size: 7pt"';
- $data['style2'] = 'style="font-size: 6pt; font-style: italic; font-weight: bold;"';
- }
- $this->load->library('lmsword');
- $this->lmsword->page_setup('A4');
- $this->lmsword->html($this->load->view('purchase/pdf', $data, true));
- $this->lmsword->create("purchase_$id");
- }
- /*
- send email
- */
- public function email($id){
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => 0,
- 'message' => 'Purchase Receipt Email Send'
- );
- $this->log_model->insert_log($log_data);
- $data = $this->purchase_model->getSupplierEmail($id);
- $company = $this->purchase_model->getCompany();
- $email = $this->purchase_model->getSmtpSetup();
- $this->load->view('class.phpmailer.php');
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->Host = $email->smtp_host;
- $mail->SMTPAuth = true;
- //$mail->SMTPSecure = "ssl";
- $mail->Port = $email->port;
- $mail->Username = $email->smtp_username;
- $mail->Password = $email->smtp_password;
- $mail->From = $email->from_address;
- $mail->FromName = $email->form_name;
- $mail->AddAddress($data[0]->email);
- //$mail->AddReplyTo("mail@mail.com");
- $mail->IsHTML(true);
- $mail->Subject = "Purchase order No : ".$data[0]->reference_no." From ".$company[0]->name;
- $mail->Body = "Date : ".$data[0]->date."<br>Total : ".$data[0]->total;
- //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
- if(!$mail->Send())
- {
- $message = "Email could not be sent";
- }
- else{
- $message = "Email has been sent";
- }
- $this->session->set_flashdata('message', $message);
- redirect('purchase','refresh');
- }
- /*
- view payment
- */
- public function payment($id){
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['items'] = $this->purchase_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['ledger'] = $this->purchase_model->getLedger();
- $data['p_reference_no'] = $this->purchase_model->generateReferenceNo();
- $this->load->view('purchase/payment',$data);
- }
- /*
- add payment
- */
- public function paymentAdd($id)
- {
- $data['data'] = $this->purchase_model->getDetails($id);
- $data['items'] = $this->purchase_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['p_reference_no'] = $this->purchase_model->generateReferenceNo();
- $this->load->view('purchase/payment/add',$data);
- }
- /*
- get Discount value for AJAX
- */
- public function getDiscountValue($id){
- $data = $this->purchase_model->getDiscountValue($id);
- echo json_encode($data);
- }
- /*
- get Tax value for AJAX
- */
- public function getTaxValue($id){
- $data = $this->purchase_model->getTaxValue($id);
- echo json_encode($data);
- }
- /*
- get payment details to view and send to model
- */
- public function addPayment()
- {
- $id = $this->input->post('id');
- $paying_by = $this->input->post('paying_by');
- $this->form_validation->set_rules('date','Date','trim|required');
- $this->form_validation->set_rules('paying_by','Paying By','trim|required');
- if($paying_by == "Cheque"){
- $this->form_validation->set_rules('bank_name','Bank Name','trim|required');
- $this->form_validation->set_rules('cheque_no','Cheque No','trim|required|numeric');
- }
- if($this->form_validation->run()==false){
- $this->payment($id);
- }
- else
- {
- if($paying_by == "Cheque"){
- $bank_name = $this->input->post('bank_name');
- $cheque_no = $this->input->post('cheque_no');
- }
- else{
- $bank_name = "";
- $cheque_no = "";
- }
- $data = array(
- "purchase_id" => $id,
- "payment_voucher_date" => $this->input->post('date'),
- "invoice_no" => $this->input->post('reference_no'),
- "payment_ledger" => $this->input->post('ledger'),
- "payment_amount" => $this->input->post('amount'),
- "mode_of_payment" => $this->input->post('paying_by'),
- "bank_name" => $bank_name,
- "cheque_no" => $cheque_no,
- "description" => $this->input->post('note')
- );
- if($this->purchase_model->addPayment($data)){
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Purchase Payable'
- );
- $this->log_model->insert_log($log_data);
- redirect('purchase','refresh');
- }
- else{
- redirect("purchase",'refresh');
- }
- }
- }
- function currencyConverter2($currency_from,$currency_to)
- {
- if($currency_from==$currency_to)
- {
- return 1;
- }
- else
- {
- //$currency_output = round(currency($currency_input, $currency_from,$currency_to, false),2);
- //$currency_input=substr($currency_input, 0, -3);
- $currency_input=filter_var(1, FILTER_SANITIZE_NUMBER_INT);
- $from_Currency = urlencode($currency_from);
- $to_Currency = urlencode($currency_to);
- $get = @file_get_contents("https://finance.google.com/finance/converter?a=1&from=$from_Currency&to=$to_Currency");
- $get = @explode("<span class=bld>",$get);
- $get = @explode("</span>",@$get[1]);
- $converted_currency = preg_replace("/[^0-9\.]/", null, @$get[0]);
- $converted_currency = $converted_currency;
- return $converted_currency;
- //return $currency_output;
- }
- }
- public function getCurrencyAjax($id) {
- $data = $this->purchase_model->getCurrencyId($id);
- echo json_encode($data);
- //print_r($data);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment