芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/www/breadwinnerv2/application/controllers/Transactions.php
load->library("Aauth"); $this->load->model('invoices_model'); $this->load->model('transactions_model', 'transactions'); if (!$this->aauth->is_loggedin()) { redirect('/user/', 'refresh'); } if ($this->aauth->get_user()->roleid < 2) { exit('
Sorry! You have insufficient permissions to access this section
'); } } public function index() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "Transaction"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/index'); $this->load->view('fixed/footer'); } public function add() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $data['cat'] = $this->transactions->categories(); $data['accounts'] = $this->transactions->acc_list(); $head['title'] = "Add Transaction"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/create', $data); $this->load->view('fixed/footer'); } public function transfer() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $data['cat'] = $this->transactions->categories(); $data['accounts'] = $this->transactions->acc_list(); $head['title'] = "New Transfer"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/transfer', $data); $this->load->view('fixed/footer'); } public function payinvoice() { if ($this->aauth->get_user()->roleid < 2) { exit('
Sorry! You have insufficient permissions to access this section
'); } $tid = intval($this->input->post('tid')); $amount = $this->input->post('amount'); $paydate = $this->input->post('paydate'); $note = $this->input->post('shortnote'); $pmethod = $this->input->post('pmethod'); $acid = $this->input->post('account'); $cid = $this->input->post('cid'); $cname = $this->input->post('cname'); $paydate = datefordatabase($paydate); $this->db->select('holder'); $this->db->from('accounts'); $this->db->where('id', $acid); $query = $this->db->get(); $account = $query->row_array(); if($pmethod=='Balance'){ $customer = $this->transactions->check_balance($cid); if($customer['balance']>=$amount){ $this->db->set('balance', "balance-$amount", FALSE); $this->db->where('id', $cid); $this->db->update('customers'); } else{ $amount=$customer['balance']; $this->db->set('balance', 0, FALSE); $this->db->where('id', $cid); $this->db->update('customers'); } } $data = array( 'acid' => $acid, 'account' => $account['holder'], 'type' => 'Income', 'cat' => 'Sales', 'credit' => $amount, 'payer' => $cname, 'payerid' => $cid, 'method' => $pmethod, 'date' => $paydate, 'eid' => $this->aauth->get_user()->id, 'tid' => $tid, 'note' => $note ); $this->db->insert('transactions', $data); //$this->db->insert_id(); $this->db->select('total,csd,pamnt'); $this->db->from('invoices'); $this->db->where('tid', $tid); $query = $this->db->get(); $invresult = $query->row(); $totalrm = $invresult->total - $invresult->pamnt; if ($totalrm > $amount) { $this->db->set('pmethod', $pmethod); $this->db->set('pamnt', "pamnt+$amount", FALSE); $this->db->set('status', 'partial'); $this->db->where('tid', $tid); $this->db->update('invoices'); //account update $this->db->set('lastbal', "lastbal+$amount", FALSE); $this->db->where('id', $acid); $this->db->update('accounts'); $paid_amount = $invresult->pamnt + $amount; $status = 'Partial'; $totalrm = $totalrm - $amount; } else { if($totalrm < $amount) { $diff=$totalrm - $amount; $diff=abs($diff); $amount=$totalrm; $this->db->set('balance', "balance+$diff", FALSE); $this->db->where('id', $cid); $this->db->update('customers'); } $this->db->set('pmethod', $pmethod); $this->db->set('pamnt', "pamnt+$totalrm", FALSE); $this->db->set('status', 'paid'); $this->db->where('tid', $tid); $this->db->update('invoices'); //account update $this->db->set('lastbal', "lastbal+$totalrm", FALSE); $this->db->where('id', $acid); $this->db->update('accounts'); $totalrm = 0; $status = 'Paid'; } $activitym = "
" . substr($paydate, 0, 10) . "
$pmethod
$amount
$note
"; echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Transaction has been added'), 'pstatus' => $this->lang->line($status), 'activity' => $activitym, 'amt' => $totalrm, 'ttlpaid' => $amount)); } public function paypurchase() { if ($this->aauth->get_user()->roleid < 3) { exit('
Sorry! You have insufficient permissions to access this section
'); } $tid = intval($this->input->post('tid')); $amount = $this->input->post('amount'); $paydate = $this->input->post('paydate'); $note = $this->input->post('shortnote'); $pmethod = $this->input->post('pmethod'); $acid = $this->input->post('account'); $cid = $this->input->post('cid'); $cname = $this->input->post('cname'); $paydate = datefordatabase($paydate); $this->db->select('holder'); $this->db->from('accounts'); $this->db->where('id', $acid); $query = $this->db->get(); $account = $query->row_array(); $data = array( 'acid' => $acid, 'account' => $account['holder'], 'type' => 'Expense', 'cat' => 'Purchase', 'debit' => $amount, 'payer' => $cname, 'payerid' => $cid, 'method' => $pmethod, 'date' => $paydate, 'eid' => $this->aauth->get_user()->id, 'tid' => $tid, 'note' => $note, 'ext' => 1 ); $this->db->insert('transactions', $data); $this->db->insert_id(); $this->db->select('total,csd,pamnt'); $this->db->from('purchase'); $this->db->where('tid', $tid); $query = $this->db->get(); $invresult = $query->row(); $totalrm = $invresult->total - $invresult->pamnt; if ($totalrm > $amount) { $this->db->set('pmethod', $pmethod); $this->db->set('pamnt', "pamnt+$amount", FALSE); $this->db->set('status', 'partial'); $this->db->where('tid', $tid); $this->db->update('purchase'); //account update $this->db->set('lastbal', "lastbal-$amount", FALSE); $this->db->where('id', $acid); $this->db->update('accounts'); $paid_amount = $invresult->pamnt + $amount; $status = 'Partial'; $totalrm = $totalrm - $amount; } else { $this->db->set('pmethod', $pmethod); $this->db->set('pamnt', "pamnt+$amount", FALSE); $this->db->set('status', 'paid'); $this->db->where('tid', $tid); $this->db->update('purchase'); //acount update $this->db->set('lastbal', "lastbal-$amount", FALSE); $this->db->where('id', $acid); $this->db->update('accounts'); $totalrm = 0; $status = 'Paid'; $paid_amount = $amount; } $activitym = "
" . substr($paydate, 0, 10) . "
$pmethod
$amount
$note
"; echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Transaction has been added'), 'pstatus' => $this->lang->line($status), 'activity' => $activitym, 'amt' => $totalrm, 'ttlpaid' => $paid_amount)); } public function pay_recinvoice() { if ($this->aauth->get_user()->roleid < 2) { exit('
Sorry! You have insufficient permissions to access this section
'); } $tid = intval($this->input->post('tid')); $amount = $this->input->post('amount'); $paydate = $this->input->post('paydate'); $note = $this->input->post('shortnote'); $pmethod = $this->input->post('pmethod'); $acid = $this->input->post('account'); $cid = $this->input->post('cid'); $cname = $this->input->post('cname'); $paydate = datefordatabase($paydate); $this->db->select('holder'); $this->db->from('accounts'); $this->db->where('id', $acid); $query = $this->db->get(); $account = $query->row_array(); $data = array( 'acid' => $acid, 'account' => $account['holder'], 'type' => 'Income', 'cat' => 'Sales', 'credit' => $amount, 'payer' => $cname, 'payerid' => $cid, 'method' => $pmethod, 'date' => $paydate, 'eid' => $this->aauth->get_user()->id, 'tid' => $tid, 'note' => $note, 'ext' => 2 ); $this->db->insert('transactions', $data); $this->db->insert_id(); $this->db->select('invoiceduedate,total,csd,pamnt,rec'); $this->db->from('rec_invoices'); $this->db->where('tid', $tid); $query = $this->db->get(); $invresult = $query->row(); $totalrm = $invresult->total - $invresult->pamnt; if ($totalrm > $amount) { $this->db->set('pmethod', $pmethod); $this->db->set('pamnt', "pamnt+$amount", FALSE); $this->db->set('status', 'partial'); $this->db->where('tid', $tid); $this->db->update('rec_invoices'); //account update $this->db->set('lastbal', "lastbal+$amount", FALSE); $this->db->where('id', $acid); $this->db->update('accounts'); $paid_amount = $invresult->pamnt + $amount; $status = 'Partial'; $totalrm = $totalrm - $amount; } else { $today = $invresult->invoiceduedate; $addday = $invresult->rec; $ndate = date("Y-m-d", strtotime($today . " +" . $addday . 's')); $this->db->set('invoiceduedate', $ndate); $this->db->set('pmethod', $pmethod); $this->db->set('pamnt', "pamnt+$amount", FALSE); $this->db->set('status', 'paid'); $this->db->where('tid', $tid); $this->db->update('rec_invoices'); //acount update $this->db->set('lastbal', "lastbal+$amount", FALSE); $this->db->where('id', $acid); $this->db->update('accounts'); $totalrm = 0; $status = 'Paid'; $paid_amount = $amount; } $activitym = "
" . substr($paydate, 0, 10) . "
$pmethod
$amount
$note
"; echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Transaction has been added'), 'pstatus' => $this->lang->line($status), 'activity' => $activitym, 'amt' => $totalrm, 'ttlpaid' => $paid_amount)); } public function cancelinvoice() { if ($this->aauth->get_user()->roleid < 2) { exit('
Sorry! You have insufficient permissions to access this section
'); } $tid = intval($this->input->post('tid')); $this->db->set('pamnt', "0.00", FALSE); $this->db->set('total', "0.00", FALSE); $this->db->set('items', 0); $this->db->set('status', 'canceled'); $this->db->where('tid', $tid); $this->db->update('invoices'); //reverse $this->db->select('credit,acid'); $this->db->from('transactions'); $this->db->where('tid', $tid); $query = $this->db->get(); $revresult = $query->result_array(); foreach ($revresult as $trans) { $amt = $trans['credit']; $this->db->set('lastbal', "lastbal-$amt", FALSE); $this->db->where('id', $trans['acid']); $this->db->update('accounts'); } $this->db->select('pid,qty'); $this->db->from('invoice_items'); $this->db->where('tid', $tid); $query = $this->db->get(); $prevresult = $query->result_array(); foreach ($prevresult as $prd) { $amt = $prd['qty']; $this->db->set('qty', "qty+$amt", FALSE); $this->db->where('pid', $prd['pid']); $this->db->update('products'); } $this->db->delete('transactions', array('tid' => $tid)); echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Invoice canceled'))); } public function cancelrec() { if ($this->aauth->get_user()->roleid < 2) { exit('
Sorry! You have insufficient permissions to access this section
'); } $tid = intval($this->input->post('tid')); $this->db->set('status', 'canceled'); $this->db->set('ron', 'Stopped'); $this->db->where('tid', $tid); $this->db->update('rec_invoices'); echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Invoice canceled'))); } public function cancelpurchase() { if ($this->aauth->get_user()->roleid < 3) { exit('
Sorry! You have insufficient permissions to access this section
'); } $tid = intval($this->input->post('tid')); $this->db->set('pamnt', "0.00", FALSE); $this->db->set('status', 'canceled'); $this->db->where('tid', $tid); $this->db->update('purchase'); //reverse $this->db->select('credit,acid'); $this->db->from('transactions'); $this->db->where('tid', $tid); $this->db->where('ext', 1); $query = $this->db->get(); $revresult = $query->result_array(); foreach ($revresult as $trans) { $amt = $trans['debit']; $this->db->set('lastbal', "lastbal+$amt", FALSE); $this->db->where('id', $trans['acid']); $this->db->update('accounts'); } $this->db->select('pid,qty'); $this->db->from('purchase_items'); $this->db->where('tid', $tid); $query = $this->db->get(); $prevresult = $query->result_array(); foreach ($prevresult as $prd) { $amt = $prd['qty']; $this->db->set('qty', "qty-$amt", FALSE); $this->db->where('pid', $prd['pid']); $this->db->update('products'); } $this->db->delete('transactions', array('tid' => $tid, 'ext' => 1)); echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Purchase canceled!'))); } public function translist() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $ttype = $this->input->get('type'); $list = $this->transactions->get_datatables($ttype); $data = array(); // $no = $_POST['start']; $no = $this->input->post('start'); foreach ($list as $prd) { $no++; $row = array(); $pid = $prd->id; $row[] = dateformat($prd->date); $row[] = $prd->account; $row[] = amountFormat($prd->debit); $row[] = amountFormat($prd->credit); $row[] = $prd->payer; $row[] = $this->lang->line($prd->method); $row[] = '
'.$this->lang->line('View').'
'; $data[] = $row; } $output = array( "draw" => $_POST['draw'], "recordsTotal" => $this->transactions->count_all(), "recordsFiltered" => $this->transactions->count_filtered(), "data" => $data, ); //output to json format echo json_encode($output); } // Category public function categories() { if ($this->aauth->get_user()->roleid < 5) { exit('
Sorry! You have insufficient permissions to access this section
'); } $data['catlist'] = $this->transactions->categories(); $head['title'] = "Category"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/cat', $data); $this->load->view('fixed/footer'); } public function createcat() { if ($this->aauth->get_user()->roleid < 5) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "Category"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/cat_create'); $this->load->view('fixed/footer'); } public function editcat() { if ($this->aauth->get_user()->roleid < 5) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "Category"; $head['usernm'] = $this->aauth->get_user()->username; $id = $this->input->get('id'); $data['cat'] = $this->transactions->cat_details($id); $this->load->view('fixed/header', $head); $this->load->view('transactions/trans-cat-edit', $data); $this->load->view('fixed/footer'); } public function save_createcat() { if ($this->aauth->get_user()->roleid < 5) { exit('
Sorry! You have insufficient permissions to access this section
'); } $name = $this->input->post('catname'); if ($this->transactions->addcat($name)) { echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('ADDED'))); } else { echo json_encode(array('status' => 'Error', 'message' => $this->lang->line('ERROR'))); } } public function editcatsave() { if ($this->aauth->get_user()->roleid < 5) { exit('
Sorry! You have insufficient permissions to access this section
'); } $id = $this->input->post('catid'); $name = $this->input->post('cat_name'); if ($this->transactions->cat_update($id, $name)) { echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('UPDATED'))); } else { echo json_encode(array('status' => 'Error', 'message' => 'Error!')); } } public function delete_cat() { if ($this->aauth->get_user()->roleid < 5) { exit('
Sorry! You have insufficient permissions to access this section
'); } $id = $this->input->post('deleteid'); if ($id) { $this->db->delete('transactions_cat', array('id' => $id)); echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('DELETED'))); } else { echo json_encode(array('status' => 'Error', 'message' => 'Error!')); } } public function save_trans() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $credit = 0; $debit = 0; $payer_id = intval($this->input->post('payer_id')); $payer_name = $this->input->post('payer_name'); $pay_acc = $this->input->post('pay_acc'); $date = $this->input->post('date'); $amount = $this->input->post('amount'); $pay_type = $this->input->post('pay_type'); if ($pay_type == 'Income') { $credit = $amount; } elseif ($pay_type == 'Expense') { $debit = $amount; } $pay_cat = $this->input->post('pay_cat'); $paymethod = $this->input->post('paymethod'); $note = $this->input->post('note'); $date = datefordatabase($date); if ($this->transactions->addtrans($payer_id, $payer_name, $pay_acc, $date, $debit, $credit, $pay_type, $pay_cat, $paymethod, $note, $this->aauth->get_user()->id)) { echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Transaction has been'))); } else { echo json_encode(array('status' => 'Error', 'message' => 'Error!')); } } public function save_transfer() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $pay_acc = $this->input->post('pay_acc'); $pay_acc2 = $this->input->post('pay_acc2'); $amount = $this->input->post('amount'); if ($this->transactions->addtransfer($pay_acc, $pay_acc2, $amount, $this->aauth->get_user()->id)) { echo json_encode(array('status' => 'Success', 'message' => 'Transfer has been successfully done!')); } else { echo json_encode(array('status' => 'Error', 'message' => 'Error!')); } } public function delete_i() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $id = $this->input->post('deleteid'); if ($id) { echo json_encode($this->transactions->delt($id)); } else { echo json_encode(array('status' => 'Error', 'message' => 'Error!')); } } public function income() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "Income Transaction"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/income'); $this->load->view('fixed/footer'); } public function expense() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "Expense Transaction"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('transactions/expense'); $this->load->view('fixed/footer'); } public function view() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "View Transaction"; $head['usernm'] = $this->aauth->get_user()->username; $id = $this->input->get('id'); $data['trans'] = $this->transactions->view($id); if ($data['trans']['payerid'] > 0) { $data['cdata'] = $this->transactions->cview($data['trans']['payerid'],$data['trans']['ext']); } else { $data['cdata'] = array('address' => 'Not Registered', 'city' => '', 'phone' => '', 'email' => ''); } $this->load->view('fixed/header', $head); $this->load->view('transactions/view', $data); $this->load->view('fixed/footer'); } public function print_t() { if ($this->aauth->get_user()->roleid < 4) { exit('
Sorry! You have insufficient permissions to access this section
'); } $head['title'] = "View Transaction"; $head['usernm'] = $this->aauth->get_user()->username; $id = $this->input->get('id'); $data['trans'] = $this->transactions->view($id); if ($data['trans']['payerid'] > 0) { $data['cdata'] = $this->transactions->cview($data['trans']['payerid'],$data['trans']['ext']); } else { $data['cdata'] = array('address' => 'Not Registered', 'city' => '', 'phone' => '', 'email' => ''); } ini_set('memory_limit', '-1'); $html = $this->load->view('transactions/view-print', $data,true); //PDF Rendering $this->load->library('pdf'); $pdf = $this->pdf->load_en(); $pdf->SetHTMLFooter('
{PAGENO}/{nbpg}
#'.$id.'
'); $pdf->WriteHTML($html); if ($this->input->get('d')) { $pdf->Output('Trans_#' . $id . '.pdf', 'D'); } else { $pdf->Output('Trans_#' . $id . '.pdf', 'I'); } } }