Ejemplo n.º 1
0
 public static function delete_invoice_item($invoice_id, $item_id)
 {
     $invoice = Invoice::find($invoice_id);
     if ($invoice) {
         $item = null;
         foreach ($invoice->items as $i) {
             if ($i->id == $item_id) {
                 $item = $i;
                 break;
             }
         }
         if ($item) {
             $item->delete();
             if (($key = array_search($item, $invoice->items)) !== false) {
                 unset($invoice->items[$key]);
             }
             $invoice_number = -1;
             foreach ($invoice->items as $i) {
                 $invoice_number = max($invoice_number, $i->reservation->id);
             }
             $invoice->invoice_number = $invoice_number;
             $invoice->update();
             Redirect::to(\Slim\Slim::getInstance()->urlFor('invoice_detail', array('id' => $invoice_id)), array('message' => 'Rivi poistettu!'));
         } else {
             Redirect::to(\Slim\Slim::getInstance()->urlFor('invoice_detail', array('id' => $invoice_id)), array('message' => 'Riviä ei ole laskulla!', 'error' => true));
         }
     } else {
         Redirect::to(\Slim\Slim::getInstance()->urlFor('invoices_index'), array('message' => 'Laskua ei löytynyt!', 'error' => true));
     }
 }
 public function order()
 {
     // Call invoice_id from CakeSession
     $invoiceId = CakeSession::read('invoice_id');
     $invoiceModel = new Invoice();
     $invoices = $invoiceModel->find('first', array('conditions' => array('Invoice.id' => $invoiceId)));
     $this->set(compact('invoices'));
 }
Ejemplo n.º 3
0
 function getInvoices()
 {
     if (!$this->invoices) {
         $finder = new Invoice();
         $this->invoices = $finder->find(array('support_contract_id' => $this->id));
     }
     return $this->invoices;
 }
Ejemplo n.º 4
0
 function actionInvoice()
 {
     $page = (int) $this->_context->get('page', 1);
     $orm = Invoice::find()->order('created desc');
     $orm->limitPage($page, 12);
     $this->_view['rs'] = $orm->getAll();
     $this->_view['pg'] = $orm->getPag();
 }
Ejemplo n.º 5
0
 /**
  * Store a newly created resource in storage.
  * POST /accountreceivables
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('invoiceID' => 'required|max:50|', 'houseID' => 'required', 'amount' => 'required|min:2', 'paymenttype' => 'required', 'amountpayed' => 'required', 'paymenttyperef' => 'required'));
     if ($v->passes()) {
         $findHouse = Input::get('houseID');
         $propertyId = House::where('name', $findHouse)->pluck('propertyID');
         $propertyName = Property::where('id', $propertyId)->pluck('name');
         $agent_id = Sentry::getUser()->id;
         $gamount = Input::get('amount');
         $gpayed = Input::get('amountpayed');
         $initpaid = Input::get('initpaid');
         $b = $gamount - $gpayed;
         $id = Input::get('invoiceID');
         $balance = $gamount - $gpayed;
         $invoice = Invoice::find($id);
         $invoiceid = $invoice->id;
         $invoice->balance = $gamount - $gpayed;
         $invoice->amountpaid = $gpayed + $initpaid;
         $invoice->save();
         $reciept = new Receipt();
         $reciept->invoiceID = $invoice->id;
         $reciept->agent_id = $agent_id;
         $reciept->type = $invoice->type;
         $reciept->houseID = $invoice->houseID;
         $reciept->recipient = $invoice->recipient;
         $reciept->invoice_amt = $gpayed + $initpaid + $b;
         $reciept->amountpaid = $gpayed;
         $reciept->balance = $gamount - $gpayed;
         $reciept->duedate = $invoice->duedate;
         $reciept->save();
         $findTenant = $invoice->recipient;
         $ftname = strtok($findTenant, " ");
         $tenants = Tenant::where('name', $ftname)->get();
         foreach ($tenants as $tenant) {
             $t_name = $tenant->name;
             $to = $tenant->phone;
         }
         $payment = new Payment();
         $payment->invoiceID = Input::get('invoiceID');
         $payment->amount = Input::get('amount');
         $payment->amountpayed = Input::get('amountpayed');
         $payment->houseID = $findHouse;
         $payment->client = $invoice->recipient;
         $payment->property = $propertyName;
         $payment->balance = $gamount - $gpayed;
         $payment->paymenttype = Input::get('paymenttype');
         $payment->paymenttyperef = Input::get('paymenttyperef');
         $payment->save();
         #send an sms to the tenant
         $message = ' Hi ' . $t_name . ', Your payment of  Ksh. ' . number_format($gpayed, 2) . ' for invoice no. ' . $invoiceid . ' of ' . $findHouse . '   has been received successfully, due balance ' . number_format($balance, 2) . ', Thank you';
         Queue::push('SendSMS', array('message' => $message, 'number' => $to));
         return Redirect::route('show/receipts/index')->withFlashMessage('Payment received successfully');
     }
     return Redirect::back()->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }
Ejemplo n.º 6
0
 private function get_invoices($_is_paid = false)
 {
     $order_by = 'issued_on asc';
     $paid_on_clause = "paid_on IS NULL";
     if ($_is_paid) {
         $paid_on_clause = "paid_on IS NOT NULL";
     }
     $criteria = array('columns' => "id, type, DATEDIFF(payable_by, now()) AS expired, \n                          DATE_FORMAT(issued_on, '%e %b, %Y') AS formatted_issued_on, \n                          DATE_FORMAT(payable_by, '%e %b, %Y') AS formatted_payable_by,\n                          DATE_FORMAT(paid_on, '%e %b, %Y') AS formatted_paid_on", 'match' => "employer = '" . $this->employer->getId() . "' AND " . $paid_on_clause, 'order' => $order_by);
     return Invoice::find($criteria);
 }
Ejemplo n.º 7
0
 private function get_employers($_for_invoice = true)
 {
     $criteria = array('columns' => "DISTINCT employers.id, employers.name AS employer", 'joins' => "employers ON employers.id = invoices.employer");
     if ($_for_invoice) {
         $criteria['match'] = "invoices.paid_on IS NULL";
     } else {
         $criteria['match'] = "invoices.paid_on IS NOT NULL";
     }
     return Invoice::find($criteria);
 }
Ejemplo n.º 8
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->__saves['UserClass'] = Configure::read('Invoices.UserClass');
     $this->__saves['idIsNumber'] = Configure::read('Invoices.idIsNumber');
     Configure::write('Invoices.UserClass', 'PluginInvoiceClient');
     Configure::write('Invoices.idIsNumber', true);
     $this->Invoice = new SpyInvoice();
     $this->Invoice->setInvoiceNumberGenerator($this->Invoice);
     $this->_record = $this->Invoice->find();
 }
Ejemplo n.º 9
0
 public function destroy($id)
 {
     $targetInvoice = Invoice::find($id);
     if ($targetInvoice) {
         $targetInvoice->delete();
         InvoiceElement::where('invoice_fk', '=', $id)->delete();
         return $this->index();
     } else {
         return $this->index();
     }
 }
Ejemplo n.º 10
0
 /**
  * Modify item to invoice
  */
 public function modify($id)
 {
     $invoice = Invoice::find($id);
     foreach ($invoice->items as $item) {
         InvoiceItem::where('id', $item->id)->update(array('ressource_id' => Input::get('ressource_id.' . $item->id), 'text' => Input::get('text.' . $item->id), 'amount' => Input::get('amount.' . $item->id), 'vat_types_id' => Input::get('vat_types_id.' . $item->id), 'order_index' => Input::get('order_index.' . $item->id)));
     }
     // Add new line
     if (Input::get('text.0')) {
         $this->add_check(array('invoice_id' => $id, 'ressource_id' => Input::get('ressource_id.0'), 'text' => Input::get('text.0'), 'amount' => Input::get('amount.0'), 'vat_types_id' => Input::get('vat_types_id.0'), 'order_index' => Input::get('order_index.0')));
     }
     return Redirect::route('invoice_modify', $id);
 }
Ejemplo n.º 11
0
 /**
  * Verify if exist
  */
 private function dataExist($id, $tpl)
 {
     if (Auth::user()->isSuperAdmin()) {
         $data = Invoice::find($id);
     } else {
         $data = Invoice::whereUserId(Auth::user()->id)->find($id);
     }
     if (!$data) {
         return Redirect::route($tpl)->with('mError', 'Cet élément est introuvable !');
     } else {
         return $data;
     }
 }
Ejemplo n.º 12
0
 function download($id = FALSE)
 {
     $this->load->helper(array('dompdf', 'file'));
     $this->load->library('parser');
     $data["invoice"] = Invoice::find($id);
     $data['items'] = InvoiceHasItem::find('all', array('conditions' => array('invoice_id=?', $id)));
     if ($data['invoice']->company_id != $this->client->company->id) {
         redirect('cinvoices');
     }
     $data["core_settings"] = Setting::first();
     $due_date = date($data["core_settings"]->date_format, human_to_unix($data["invoice"]->due_date . ' 00:00:00'));
     $parse_data = array('due_date' => $due_date, 'invoice_id' => $data["invoice"]->reference, 'client_link' => $data["core_settings"]->domain, 'company' => $data["core_settings"]->company);
     $html = $this->load->view($data["core_settings"]->template . '/' . 'invoices/preview', $data, true);
     $html = $this->parser->parse_string($html, $parse_data);
     $filename = 'Invoice_' . $data["invoice"]->reference;
     pdf_create($html, $filename, TRUE);
 }
Ejemplo n.º 13
0
function get_payments($_is_invoice = true, $_order = "invoices.issued_on", $_employer_to_filter = '')
{
    $criteria = array("columns" => "invoices.id, invoices.type, invoices.payable_by,\n                      employers.name AS employer, employers.contact_person, employers.email_addr, \n                      employers.fax_num, employers.phone_num, 'N/A' AS placement, \n                      SUM(invoice_items.amount) AS amount_payable, currencies.symbol AS currency, \n                      DATE_FORMAT(invoices.issued_on, '%e %b, %Y') AS formatted_issued_on, \n                      DATE_FORMAT(invoices.payable_by, '%e %b, %Y') AS formatted_payable_by,\n                      DATE_FORMAT(invoices.paid_on, '%e %b, %Y') AS formatted_paid_on", "joins" => "employers ON employers.id = invoices.employer, \n                    branches ON branches.id = employers.branch, \n                    invoice_items ON invoice_items.invoice = invoices.id, \n                    currencies ON currencies.country_code = branches.country", "group" => "invoices.id", "order" => $_order);
    if ($_is_invoice) {
        $criteria['match'] = "invoices.paid_on IS NULL AND invoices.is_copy = FALSE";
    } else {
        $criteria['columns'] .= ", invoices.paid_through, invoices.paid_id";
        $criteria['match'] = "invoices.paid_on IS NOT NULL AND invoices.is_copy = FALSE";
    }
    if (!empty($_employer_to_filter)) {
        $criteria['match'] .= " AND invoices.employer = '" . $_employer_to_filter . "'";
    }
    $invoices = Invoice::find($criteria);
    if (empty($invoices) || is_null($invoices) || $invoices === false) {
        return array();
    }
    $invoice_ids = array();
    foreach ($invoices as $row) {
        $invoice_ids[] = $row['id'];
    }
    $criteria = array('columns' => "DISTINCT invoices.id, invoice_items.item, referrals.job, jobs.title, \n                      CONCAT(members.lastname, ', ', members.firstname) AS candidate", 'joins' => "invoice_items ON invoice_items.invoice = invoices.id, \n                    referrals ON referrals.id = invoice_items.item,\n                    jobs ON jobs.id = referrals.job, \n                    members ON members.email_addr = referrals.referee", 'match' => "invoices.is_copy = FALSE AND invoices.type = 'R' AND \n                    invoices.id IN (" . implode(',', $invoice_ids) . ")");
    $result = Invoice::find($criteria);
    if (empty($result) || is_null($result) || $iresult === false) {
        return $invoices;
    }
    foreach ($invoices as $i => $invoice) {
        foreach ($result as $row) {
            if ($row['id'] == $invoice['id']) {
                if (is_null($row['job']) || empty($row['job']) || (is_null($row['candidate']) || empty($row['candidate'])) || (is_null($row['title']) || empty($row['title']))) {
                    $invoices[$i]['placement'] = '(Data is missing)';
                    break;
                }
                $invoices[$i]['placement'] = htmlspecialchars_decode(stripslashes($row['title'])) . ' to ';
                $invoices[$i]['placement'] .= htmlspecialchars_decode(stripslashes($row['candidate']));
                break;
            }
        }
    }
    return $invoices;
}
Ejemplo n.º 14
0
 function view($id = FALSE)
 {
     $this->view_data['submenu'] = array($this->lang->line('application_back') => 'cprojects', $this->lang->line('application_overview') => 'cprojects/view/' . $id, $this->lang->line('application_media') => 'cprojects/media/' . $id);
     $this->view_data['project'] = Project::find($id);
     $this->view_data['project_has_invoices'] = Invoice::find('all', array('conditions' => array('project_id = ? AND company_id=? AND estimate != ? AND issue_date<=?', $id, $this->client->company->id, 1, date('Y-m-d', time()))));
     $tasks = ProjectHasTask::count(array('conditions' => 'project_id = ' . $id));
     $tasks_done = ProjectHasTask::count(array('conditions' => array('status = ? AND project_id = ?', 'done', $id)));
     @($this->view_data['opentaskspercent'] = $tasks_done / $tasks * 100);
     $this->view_data['time_days'] = round((human_to_unix($this->view_data['project']->end . ' 00:00') - human_to_unix($this->view_data['project']->start . ' 00:00')) / 3600 / 24);
     $this->view_data['time_left'] = $this->view_data['time_days'];
     $this->view_data['timeleftpercent'] = 100;
     if (human_to_unix($this->view_data['project']->start . ' 00:00') < time() && human_to_unix($this->view_data['project']->end . ' 00:00') > time()) {
         $this->view_data['time_left'] = round((human_to_unix($this->view_data['project']->end . ' 00:00') - time()) / 3600 / 24);
         $this->view_data['timeleftpercent'] = $this->view_data['time_left'] / $this->view_data['time_days'] * 100;
     }
     if (human_to_unix($this->view_data['project']->end . ' 00:00') < time()) {
         $this->view_data['time_left'] = 0;
         $this->view_data['timeleftpercent'] = 0;
     }
     @($this->view_data['opentaskspercent'] = $tasks_done / $tasks * 100);
     $tracking = $this->view_data['project']->time_spent;
     if (!empty($this->view_data['project']->tracking)) {
         $tracking = time() - $this->view_data['project']->tracking + $this->view_data['project']->time_spent;
     }
     $this->view_data['timertime'] = $tracking;
     $this->view_data['time_spent_from_today'] = time() - $this->view_data['project']->time_spent;
     $tracking = floor($tracking / 60);
     $tracking_hours = floor($tracking / 60);
     $tracking_minutes = $tracking - $tracking_hours * 60;
     $this->view_data['time_spent'] = $tracking_hours . " " . $this->lang->line('application_hours') . " " . $tracking_minutes . " " . $this->lang->line('application_minutes');
     $this->view_data['time_spent_counter'] = sprintf("%02s", $tracking_hours) . ":" . sprintf("%02s", $tracking_minutes);
     if (!isset($this->view_data['project_has_invoices'])) {
         $this->view_data['project_has_invoices'] = array();
     }
     if ($this->view_data['project']->company_id != $this->client->company->id) {
         redirect('cprojects');
     }
     $this->content_view = 'projects/client_views/view';
 }
Ejemplo n.º 15
0
 /**
  * Store a newly created resource in storage.
  * POST /accountreceivables
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('invoiceID' => 'required|max:50|', 'houseID' => 'required', 'amount' => 'required|min:2', 'paymenttype' => 'required', 'amountpayed' => 'required', 'paymenttyperef' => 'required'));
     if ($v->passes()) {
         $gamount = Input::get('amount');
         $gpayed = Input::get('amountpayed');
         $initpaid = Input::get('initpaid');
         $id = Input::get('invoiceID');
         $balance = $gamount - $gpayed;
         $invoice = Invoice::find($id);
         $invoice->balance = $gamount - $gpayed;
         $invoice->amountpaid = $gpayed + $initpaid;
         $invoice->save();
         $payment = new Payment();
         $payment->invoiceID = Input::get('invoiceID');
         $payment->amount = Input::get('amount');
         $payment->amountpayed = Input::get('amountpayed');
         $payment->houseID = Input::get('houseID');
         $payment->balance = $gamount - $gpayed;
         $payment->paymenttype = Input::get('paymenttype');
         $payment->paymenttyperef = Input::get('paymenttyperef');
         $payment->save();
         #send an sms to the tenant
         $findTenant = $invoice->recipient;
         $tenants = Tenant::where('name', $findTenant)->get();
         foreach ($tenants as $tenant) {
             $t_name = $tenant->name;
             $to = $tenant->phone;
         }
         $message = ' Hi ' . $t_name . ', Your invoivce Payment  of amount: Ksh. ' . number_format($gpayed, 2) . ' has been received  due balance ' . number_format($balance, 2) . ', Thank you for Choosing us';
         LaravelAtApi::sendMessage($to, $message);
         return Redirect::route('admin.invoice.show', $id);
     }
     return Redirect::back()->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }
Ejemplo n.º 16
0
 function view($id = FALSE)
 {
     $this->view_data['submenu'] = array($this->lang->line('application_back') => 'clients');
     $this->view_data['company'] = Company::find($id);
     $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('estimate != ? AND company_id = ? AND estimate_status != ?', 1, $id, 'Declined')));
     $this->content_view = 'clients/view';
 }
Ejemplo n.º 17
0
 private function sendInvoiceToContact($id, $date, $nit, $mail_to)
 {
     $link_object = array('id' => $id, 'random_string' => "thiIsARandomString,YouNeedToChangeIt", 'date' => $date, 'nit' => $nit);
     $link_object = json_encode($link_object);
     $idnew = base64_encode($link_object);
     //base64_encode(1);
     $invoice = Invoice::find($id);
     foreach ($mail_to as $key => $m_to) {
         global $ma_to;
         $ma_to = $m_to;
         Mail::send('emails.wellcome', array('link' => 'www.sigcfactu.com.bo/clientefactura/' . $idnew, 'cliente' => $invoice->client_name, 'nit' => $invoice->client_nit, 'monto' => $invoice->importe_total, 'numero_factura' => $invoice->invoice_number), function ($message) {
             global $ma_to;
             $message->to($ma_to, '')->subject('Factura');
         });
     }
     return 0;
 }
Ejemplo n.º 18
0
 function stripepay($id = FALSE, $sum = FALSE)
 {
     $data["core_settings"] = Setting::first();
     $stripe_keys = array("secret_key" => $data["core_settings"]->stripe_p_key, "publishable_key" => $data["core_settings"]->stripe_key);
     if ($_POST) {
         unset($_POST['send']);
         $invoice = Invoice::find($_POST['id']);
         // Stores errors:
         $errors = array();
         // Need a payment token:
         if (isset($_POST['stripeToken'])) {
             $token = $_POST['stripeToken'];
             // Check for a duplicate submission, just in case:
             // Uses sessions, you could use a cookie instead.
             if (isset($_SESSION['token']) && $_SESSION['token'] == $token) {
                 $errors['token'] = 'You have apparently resubmitted the form. Please do not do that.';
                 $this->session->set_flashdata('message', 'error: You have apparently resubmitted the form. Please do not do that.');
             } else {
                 // New submission.
                 $_SESSION['token'] = $token;
             }
         } else {
             $this->session->set_flashdata('message', 'error: The order cannot be processed. Please make sure you have JavaScript enabled and try again.');
             $errors['token'] = 'The order cannot be processed. Please make sure you have JavaScript enabled and try again.';
             log_message('error', 'Stripe: ERROR - Payment canceled for invoice #' . $invoice->reference . '.');
         }
         // Set the order amount somehow:
         $sum_exp = explode('.', $_POST['sum']);
         $amount = $sum_exp[0] * 100 + $sum_exp[1];
         // in cents
         //Get currency
         # PHP ISO currency => name list
         $currency = $invoice->currency;
         $currency_codes = array("AFA" => "Afghani", "AFN" => "Afghani", "ALK" => "Albanian old lek", "ALL" => "Lek", "DZD" => "Algerian Dinar", "USD" => "US Dollar", "ADF" => "Andorran Franc", "ADP" => "Andorran Peseta", "EUR" => "Euro", "AOR" => "Angolan Kwanza Readjustado", "AON" => "Angolan New Kwanza", "AOA" => "Kwanza", "XCD" => "East Caribbean Dollar", "ARA" => "Argentine austral", "ARS" => "Argentine Peso", "ARL" => "Argentine peso ley", "ARM" => "Argentine peso moneda nacional", "ARP" => "Peso argentino", "AMD" => "Armenian Dram", "AWG" => "Aruban Guilder", "AUD" => "Australian Dollar", "ATS" => "Austrian Schilling", "AZM" => "Azerbaijani manat", "AZN" => "Azerbaijanian Manat", "BSD" => "Bahamian Dollar", "BHD" => "Bahraini Dinar", "BDT" => "Taka", "BBD" => "Barbados Dollar", "BYR" => "Belarussian Ruble", "BEC" => "Belgian Franc (convertible)", "BEF" => "Belgian Franc (currency union with LUF)", "BEL" => "Belgian Franc (financial)", "BZD" => "Belize Dollar", "XOF" => "CFA Franc BCEAO", "BMD" => "Bermudian Dollar", "INR" => "Indian Rupee", "BTN" => "Ngultrum", "BOP" => "Bolivian peso", "BOB" => "Boliviano", "BOV" => "Mvdol", "BAM" => "Convertible Marks", "BWP" => "Pula", "NOK" => "Norwegian Krone", "BRC" => "Brazilian cruzado", "BRB" => "Brazilian cruzeiro", "BRL" => "Brazilian Real", "BND" => "Brunei Dollar", "BGN" => "Bulgarian Lev", "BGJ" => "Bulgarian lev A/52", "BGK" => "Bulgarian lev A/62", "BGL" => "Bulgarian lev A/99", "BIF" => "Burundi Franc", "KHR" => "Riel", "XAF" => "CFA Franc BEAC", "CAD" => "Canadian Dollar", "CVE" => "Cape Verde Escudo", "KYD" => "Cayman Islands Dollar", "CLP" => "Chilean Peso", "CLF" => "Unidades de fomento", "CNX" => "Chinese People's Bank dollar", "CNY" => "Yuan Renminbi", "COP" => "Colombian Peso", "COU" => "Unidad de Valor real", "KMF" => "Comoro Franc", "CDF" => "Franc Congolais", "NZD" => "New Zealand Dollar", "CRC" => "Costa Rican Colon", "HRK" => "Croatian Kuna", "CUP" => "Cuban Peso", "CYP" => "Cyprus Pound", "CZK" => "Czech Koruna", "CSK" => "Czechoslovak koruna", "CSJ" => "Czechoslovak koruna A/53", "DKK" => "Danish Krone", "DJF" => "Djibouti Franc", "DOP" => "Dominican Peso", "ECS" => "Ecuador sucre", "EGP" => "Egyptian Pound", "SVC" => "Salvadoran colón", "EQE" => "Equatorial Guinean ekwele", "ERN" => "Nakfa", "EEK" => "Kroon", "ETB" => "Ethiopian Birr", "FKP" => "Falkland Island Pound", "FJD" => "Fiji Dollar", "FIM" => "Finnish Markka", "FRF" => "French Franc", "XFO" => "Gold-Franc", "XPF" => "CFP Franc", "GMD" => "Dalasi", "GEL" => "Lari", "DDM" => "East German Mark of the GDR (East Germany)", "DEM" => "Deutsche Mark", "GHS" => "Ghana Cedi", "GHC" => "Ghanaian cedi", "GIP" => "Gibraltar Pound", "GRD" => "Greek Drachma", "GTQ" => "Quetzal", "GNF" => "Guinea Franc", "GNE" => "Guinean syli", "GWP" => "Guinea-Bissau Peso", "GYD" => "Guyana Dollar", "HTG" => "Gourde", "HNL" => "Lempira", "HKD" => "Hong Kong Dollar", "HUF" => "Forint", "ISK" => "Iceland Krona", "ISJ" => "Icelandic old krona", "IDR" => "Rupiah", "IRR" => "Iranian Rial", "IQD" => "Iraqi Dinar", "IEP" => "Irish Pound (Punt in Irish language)", "ILP" => "Israeli lira", "ILR" => "Israeli old sheqel", "ILS" => "New Israeli Sheqel", "ITL" => "Italian Lira", "JMD" => "Jamaican Dollar", "JPY" => "Yen", "JOD" => "Jordanian Dinar", "KZT" => "Tenge", "KES" => "Kenyan Shilling", "KPW" => "North Korean Won", "KRW" => "Won", "KWD" => "Kuwaiti Dinar", "KGS" => "Som", "LAK" => "Kip", "LAJ" => "Lao kip", "LVL" => "Latvian Lats", "LBP" => "Lebanese Pound", "LSL" => "Loti", "ZAR" => "Rand", "LRD" => "Liberian Dollar", "LYD" => "Libyan Dinar", "CHF" => "Swiss Franc", "LTL" => "Lithuanian Litas", "LUF" => "Luxembourg Franc (currency union with BEF)", "MOP" => "Pataca", "MKD" => "Denar", "MKN" => "Former Yugoslav Republic of Macedonia denar A/93", "MGA" => "Malagasy Ariary", "MGF" => "Malagasy franc", "MWK" => "Kwacha", "MYR" => "Malaysian Ringgit", "MVQ" => "Maldive rupee", "MVR" => "Rufiyaa", "MAF" => "Mali franc", "MTL" => "Maltese Lira", "MRO" => "Ouguiya", "MUR" => "Mauritius Rupee", "MXN" => "Mexican Peso", "MXP" => "Mexican peso", "MXV" => "Mexican Unidad de Inversion (UDI)", "MDL" => "Moldovan Leu", "MCF" => "Monegasque franc (currency union with FRF)", "MNT" => "Tugrik", "MAD" => "Moroccan Dirham", "MZN" => "Metical", "MZM" => "Mozambican metical", "MMK" => "Kyat", "NAD" => "Namibia Dollar", "NPR" => "Nepalese Rupee", "NLG" => "Netherlands Guilder", "ANG" => "Netherlands Antillian Guilder", "NIO" => "Cordoba Oro", "NGN" => "Naira", "OMR" => "Rial Omani", "PKR" => "Pakistan Rupee", "PAB" => "Balboa", "PGK" => "Kina", "PYG" => "Guarani", "YDD" => "South Yemeni dinar", "PEN" => "Nuevo Sol", "PEI" => "Peruvian inti", "PEH" => "Peruvian sol", "PHP" => "Philippine Peso", "PLZ" => "Polish zloty A/94", "PLN" => "Zloty", "PTE" => "Portuguese Escudo", "TPE" => "Portuguese Timorese escudo", "QAR" => "Qatari Rial", "RON" => "New Leu", "ROL" => "Romanian leu A/05", "ROK" => "Romanian leu A/52", "RUB" => "Russian Ruble", "RWF" => "Rwanda Franc", "SHP" => "Saint Helena Pound", "WST" => "Tala", "STD" => "Dobra", "SAR" => "Saudi Riyal", "RSD" => "Serbian Dinar", "CSD" => "Serbian Dinar", "SCR" => "Seychelles Rupee", "SLL" => "Leone", "SGD" => "Singapore Dollar", "SKK" => "Slovak Koruna", "SIT" => "Slovenian Tolar", "SBD" => "Solomon Islands Dollar", "SOS" => "Somali Shilling", "ZAL" => "South African financial rand (Funds code) (discont", "ESP" => "Spanish Peseta", "ESA" => "Spanish peseta (account A)", "ESB" => "Spanish peseta (account B)", "LKR" => "Sri Lanka Rupee", "SDD" => "Sudanese Dinar", "SDP" => "Sudanese Pound", "SDG" => "Sudanese Pound", "SRD" => "Surinam Dollar", "SRG" => "Suriname guilder", "SZL" => "Lilangeni", "SEK" => "Swedish Krona", "CHE" => "WIR Euro", "CHW" => "WIR Franc", "SYP" => "Syrian Pound", "TWD" => "New Taiwan Dollar", "TJS" => "Somoni", "TJR" => "Tajikistan ruble", "TZS" => "Tanzanian Shilling", "THB" => "Baht", "TOP" => "Pa'anga", "TTD" => "Trinidata and Tobago Dollar", "TND" => "Tunisian Dinar", "TRY" => "New Turkish Lira", "TRL" => "Turkish lira A/05", "TMM" => "Manat", "RUR" => "Russian rubleA/97", "SUR" => "Soviet Union ruble", "UGX" => "Uganda Shilling", "UGS" => "Ugandan shilling A/87", "UAH" => "Hryvnia", "UAK" => "Ukrainian karbovanets", "AED" => "UAE Dirham", "GBP" => "Pound Sterling", "USN" => "US Dollar (Next Day)", "USS" => "US Dollar (Same Day)", "UYU" => "Peso Uruguayo", "UYN" => "Uruguay old peso", "UYI" => "Uruguay Peso en Unidades Indexadas", "UZS" => "Uzbekistan Sum", "VUV" => "Vatu", "VEF" => "Bolivar Fuerte", "VEB" => "Venezuelan Bolivar", "VND" => "Dong", "VNC" => "Vietnamese old dong", "YER" => "Yemeni Rial", "YUD" => "Yugoslav Dinar", "YUM" => "Yugoslav dinar (new)", "ZRN" => "Zairean New Zaire", "ZRZ" => "Zairean Zaire", "ZMK" => "Kwacha", "ZWD" => "Zimbabwe Dollar", "ZWC" => "Zimbabwe Rhodesian dollar");
         if (!array_key_exists($currency, $currency_codes)) {
             $currency = $data["core_settings"]->stripe_currency;
         }
         // Validate other form data!
         // If no errors, process the order:
         if (empty($errors)) {
             // create the charge on Stripe's servers - this will charge the user's card
             try {
                 // Include the Stripe library:
                 $this->load->file(APPPATH . 'helpers/stripe/lib/Stripe.php', true);
                 // set your secret key
                 // see your keys here https://manage.stripe.com/account
                 Stripe::setApiKey($stripe_keys["secret_key"]);
                 // Charge the order:
                 $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => $currency, "card" => $token, "description" => $invoice->reference));
                 // Check that it was paid:
                 if ($charge->paid == true) {
                     $attr = array();
                     $paid_date = date('Y-m-d', time());
                     $payment_reference = $invoice->reference . '00' . InvoiceHasPayment::count(array('conditions' => 'invoice_id = ' . $invoice->id)) + 1;
                     $attributes = array('invoice_id' => $invoice->id, 'reference' => $payment_reference, 'amount' => $_POST['sum'], 'date' => $paid_date, 'type' => 'credit_card', 'notes' => '');
                     $invoiceHasPayment = InvoiceHasPayment::create($attributes);
                     $invoice->update_attributes(array('paid_date' => $paid_date, 'status' => 'Paid'));
                     $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_payment_complete'));
                     log_message('error', 'Stripe: Payment for Invoice #' . $invoice->reference . ' successfully made');
                 } else {
                     // Charge was not paid!
                     $this->session->set_flashdata('message', 'error: Your payment could NOT be processed (i.e., you have not been charged) because the payment system rejected the transaction.');
                     log_message('error', 'Stripe: ERROR - Payment for Invoice #' . $invoice->reference . ' was not successful!');
                 }
             } catch (Stripe_CardError $e) {
                 // Card was declined.
                 $e_json = $e->getJsonBody();
                 $err = $e_json['error'];
                 $errors['stripe'] = $err['message'];
                 $this->session->set_flashdata('message', 'error: Card was declined!');
                 log_message('error', 'Stripe: ERROR - Credit Card was declined by Stripe! Payment process canceled for invoice #' . $invoice->reference . '.');
             } catch (Stripe_ApiConnectionError $e) {
                 // Network problem, perhaps try again.
             } catch (Stripe_InvalidRequestError $e) {
             } catch (Stripe_ApiError $e) {
                 // Stripe's servers are down!
             } catch (Stripe_CardError $e) {
                 // Something else that's not the customer's fault.
             }
         } else {
             $this->session->set_flashdata('message', 'error: ' . $errors["token"]);
             log_message('error', 'Stripe: ' . $errors["token"]);
         }
         redirect('cinvoices/view/' . $_POST['id']);
     } else {
         $this->view_data['invoices'] = Invoice::find_by_id($id);
         $this->view_data['public_key'] = $data["core_settings"]->stripe_key;
         $this->view_data['sum'] = $sum;
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_pay_with_credit_card');
         $this->view_data['form_action'] = 'cinvoices/stripepay';
         $this->content_view = 'invoices/_stripe';
     }
 }
Ejemplo n.º 19
0
 function preview($id = FALSE)
 {
     $this->load->helper(array('dompdf', 'file'));
     $this->load->library('parser');
     $data["estimate"] = Invoice::find($id);
     $data['items'] = InvoiceHasItem::find('all', array('conditions' => array('invoice_id=?', $id)));
     $data["core_settings"] = Setting::first();
     $due_date = date($data["core_settings"]->date_format, human_to_unix($data["estimate"]->due_date . ' 00:00:00'));
     $parse_data = array('due_date' => $due_date, 'estimate_id' => $data["estimate"]->reference, 'client_link' => $data["core_settings"]->domain, 'company' => $data["core_settings"]->company);
     $html = $this->load->view($data["core_settings"]->template . '/' . $data["core_settings"]->estimate_pdf_template, $data, true);
     $html = $this->parser->parse_string($html, $parse_data);
     $filename = $this->lang->line('application_estimate') . '_' . $data["core_settings"]->estimate_prefix . $data["estimate"]->reference;
     pdf_create($html, $filename, TRUE);
 }
Ejemplo n.º 20
0
 function getInvoices()
 {
     if (empty($this->invoices)) {
         $finder = new Invoice();
         $this->invoices = $finder->find(array('project_id' => $this->id));
     }
     return $this->invoices;
 }
 /**
  * Show the form for editing the specified quote.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     if (!Sentry::getUser()) {
         return Redirect::route('sessions.create');
     }
     $quote = Invoice::find($id);
     return View::make('invoices.edit', compact('quote'));
 }
 function auto_generate_number($type)
 {
     $value = "";
     if ($type == "Quote") {
         App::uses('Quote', 'QuoteManager.Model');
         $quoteModel = new Quote();
         $quotes = $quoteModel->find('all', array('fields' => array('Quote.id,Quote.quote_number')));
         if ($quotes) {
             $quote_number = (int) $quotes[count($quotes) - 1]['Quote']['quote_number'];
             $cnt = count($quotes);
             $max = 0;
             for ($i = 1; $i <= $cnt; $i++) {
                 $num = (int) $quotes[$i - 1]['Quote']['quote_number'];
                 if ($max < $num) {
                     $max = $num;
                 }
             }
             $quote_number = explode("-", $quote_number);
             $length = strlen($quote_number[0] + 1) == strlen($quote_number[0]) ? strlen($quote_number[0]) : strlen($quote_number[0] + 1);
             for ($i = $length; $i < 6; $i++) {
                 $value .= '0';
             }
             //$value.=$quote_number[0] + 1;
             $value .= $max + 1;
         } else {
             $value = "000001";
         }
     } elseif ($type == "Work Order") {
         App::uses('WorkOrder', 'WorkOrderManager.Model');
         $woModel = new WorkOrder();
         $wos = $woModel->find('all', array('fields' => array('WorkOrder.id,work_order_number')));
         if ($wos) {
             $wo_number = (int) $wos[count($wos) - 1]['WorkOrder']['work_order_number'];
             $length = strlen($wo_number + 1) == strlen($wo_number) ? strlen($wo_number) : strlen($wo_number + 1);
             for ($i = $length; $i < 6; $i++) {
                 $value .= '0';
             }
             $value .= $wo_number + 1;
         } else {
             $value = "000001";
         }
     } elseif ($type == "Purchase Order") {
         App::uses('PurchaseOrder', 'PurchaseOrderManager.Model');
         $poModel = new PurchaseOrder();
         $pos = $poModel->find('all', array('fields' => array('PurchaseOrder.id,purchase_order_num')));
         if ($pos) {
             $po_number = (int) $pos[count($pos) - 1]['PurchaseOrder']['purchase_order_num'];
             $length = strlen($po_number + 1) == strlen($po_number) ? strlen($po_number) : strlen($po_number + 1);
             for ($i = $length; $i < 6; $i++) {
                 $value .= '0';
             }
             $value .= $po_number + 1;
         } else {
             $value = "000001";
         }
     } elseif ($type == "Invoice") {
         App::uses('Invoice', 'Invoice.Model');
         $invoiceModel = new Invoice();
         $invoice = $invoiceModel->find('all', array('fields' => array('Invoice.id,invoice_no')));
         if ($invoice) {
             $invoice_number = (int) $invoice[count($invoice) - 1]['Invoice']['invoice_no'];
             $length = strlen($invoice_number + 1) == strlen($invoice_number) ? strlen($invoice_number) : strlen($invoice_number + 1);
             for ($i = $length; $i < 6; $i++) {
                 $value .= '0';
             }
             $value .= $invoice_number + 1;
         } else {
             $value = "000001";
         }
     }
     return $value;
 }
Ejemplo n.º 23
0
 public function destroy($id)
 {
     House::find($id)->delete();
     Invoice::find($id)->delete();
     return Redirect::route('invoice');
 }
Ejemplo n.º 24
0
 function item($id = FALSE)
 {
     if ($_POST) {
         unset($_POST['send']);
         $_POST = array_map('htmlspecialchars', $_POST);
         if ($_POST['name'] != "") {
             $_POST['name'] = $_POST['name'];
             $_POST['value'] = $_POST['value'];
             $_POST['type'] = $_POST['type'];
         } else {
             if ($_POST['item_id'] == "-") {
                 $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
                 redirect('estimates/view/' . $_POST['invoice_id']);
             } else {
                 $itemvalue = Item::find_by_id($_POST['item_id']);
                 $_POST['name'] = $itemvalue->name;
                 $_POST['type'] = $itemvalue->type;
                 $_POST['value'] = $itemvalue->value;
             }
         }
         $item = InvoiceHasItem::create($_POST);
         if (!$item) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_add_item_success'));
         }
         redirect('estimates/view/' . $_POST['invoice_id']);
     } else {
         $this->view_data['estimate'] = Invoice::find($id);
         $this->view_data['items'] = Item::find('all', array('conditions' => array('inactive=?', '0')));
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_add_item');
         $this->view_data['form_action'] = 'estimates/item';
         $this->content_view = 'estimates/_item';
     }
 }
Ejemplo n.º 25
0
 function index()
 {
     $this->theme_view = 'blank';
     $this->load->helper(array('dompdf', 'file'));
     $timestamp = time();
     $core_settings = Setting::first();
     $date = date("Y-m-d");
     if ($core_settings->cronjob == "1" && time() > $core_settings->last_cronjob + 300) {
         $core_settings->last_cronjob = time();
         $core_settings->save();
         $this->load->database();
         //Check Subscriptions
         $sql = 'SELECT * FROM subscriptions WHERE status != "Inactive" AND end_date > "' . $date . '" AND "' . $date . '" >= next_payment ORDER BY next_payment';
         $res = $this->db->query($sql);
         $res = $res->result();
         foreach ($res as $key2 => $value2) {
             $eventline = 'New invoice created for subscription <a href="' . base_url() . 'subscriptions/view/' . $value2->id . '">#' . $value2->reference . '</a>';
             $subscription = Subscription::find($value2->id);
             $invoice = Invoice::last();
             $invoice_reference = Setting::first();
             if ($subscription) {
                 $_POST['subscription_id'] = $subscription->id;
                 $_POST['company_id'] = $subscription->company_id;
                 if ($subscription->subscribed != 0) {
                     $_POST['status'] = "Paid";
                 } else {
                     $_POST['status'] = "Open";
                 }
                 $_POST['currency'] = $subscription->currency;
                 $_POST['issue_date'] = $subscription->next_payment;
                 $_POST['due_date'] = date('Y-m-d', strtotime('+3 day', strtotime($subscription->next_payment)));
                 $_POST['currency'] = $subscription->currency;
                 $_POST['terms'] = $subscription->terms;
                 $_POST['discount'] = $subscription->discount;
                 $_POST['reference'] = $invoice_reference->invoice_reference;
                 $invoice = Invoice::create($_POST);
                 $invoiceid = Invoice::last();
                 $items = SubscriptionHasItem::find('all', array('conditions' => array('subscription_id=?', $value2->id)));
                 foreach ($items as $value) {
                     $itemvalues = array('invoice_id' => $invoiceid->id, 'item_id' => $value->item_id, 'amount' => $value->amount, 'description' => $value->description, 'value' => $value->value, 'name' => $value->name, 'type' => $value->type);
                     InvoiceHasItem::create($itemvalues);
                 }
                 $invoice_reference->update_attributes(array('invoice_reference' => $invoice_reference->invoice_reference + 1));
                 if ($invoice) {
                     $subscription->next_payment = date('Y-m-d', strtotime($subscription->frequency, strtotime($subscription->next_payment)));
                     $subscription->save();
                     //Send Invoice to Client via email
                     $this->load->library('parser');
                     $data["invoice"] = Invoice::find($invoiceid->id);
                     $data['items'] = InvoiceHasItem::find('all', array('conditions' => array('invoice_id=?', $invoiceid->id)));
                     $data["core_settings"] = Setting::first();
                     // Generate PDF
                     $html = $this->load->view($data["core_settings"]->template . '/' . 'invoices/preview', $data, true);
                     $filename = $this->lang->line('application_invoice') . '_' . $data["invoice"]->reference;
                     pdf_create($html, $filename, FALSE);
                     //email
                     $this->email->from($data["core_settings"]->email, $data["core_settings"]->company);
                     $this->email->to($data["invoice"]->company->client->email);
                     $this->email->subject($data["core_settings"]->invoice_mail_subject);
                     $this->email->attach("files/temp/" . $filename . ".pdf");
                     $due_date = date($data["core_settings"]->date_format, human_to_unix($data["invoice"]->due_date . ' 00:00:00'));
                     //Set parse values
                     $parse_data = array('client_contact' => $data["invoice"]->company->client->firstname . ' ' . $data["invoice"]->company->client->lastname, 'due_date' => $due_date, 'invoice_id' => $data["invoice"]->reference, 'client_link' => $data["core_settings"]->domain, 'company' => $data["core_settings"]->company, 'logo' => '<img src="' . base_url() . '' . $data["core_settings"]->logo . '" alt="' . $data["core_settings"]->company . '"/>', 'invoice_logo' => '<img src="' . base_url() . '' . $data["core_settings"]->invoice_logo . '" alt="' . $data["core_settings"]->company . '"/>');
                     $email_invoice = read_file('./application/views/' . $data["core_settings"]->template . '/templates/email_invoice.html');
                     $message = $this->parser->parse_string($email_invoice, $parse_data);
                     $this->email->message($message);
                     if ($this->email->send()) {
                         $data["invoice"]->update_attributes(array('status' => 'Sent', 'sent_date' => date("Y-m-d")));
                     }
                     log_message('error', $eventline);
                     unlink("files/temp/" . $filename . ".pdf");
                 }
             }
         }
         //Check Subscriptions end
         // Auto Backup every 7 days
         if ($core_settings->autobackup == "1" && time() > $core_settings->last_autobackup + 7 * 24 * 60 * 60) {
             $this->load->dbutil();
             $prefs = array('format' => 'zip', 'filename' => 'Database-auto-full-backup_' . date('Y-m-d_H-i'));
             $backup =& $this->dbutil->backup($prefs);
             if (!write_file('./files/backup/Database-auto-full-backup_' . date('Y-m-d_H-i') . '.zip', $backup)) {
                 log_message('error', "Error while creating auto database backup!");
             } else {
                 $core_settings->last_autobackup = time();
                 $core_settings->save();
                 log_message('error', "Auto backup has been created.");
             }
         }
         echo "Success";
     }
 }
Ejemplo n.º 26
0
 function item($id = FALSE)
 {
     if ($_POST) {
         unset($_POST['send']);
         $_POST = array_map('htmlspecialchars', $_POST);
         if ($_POST['name'] != "") {
             $_POST['name'] = $_POST['name'];
             $_POST['value'] = $_POST['value'];
             $_POST['type'] = $_POST['type'];
         } else {
             if ($_POST['item_id'] == "-") {
                 $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
                 redirect('invoices/view/' . $_POST['invoice_id']);
             } else {
                 $rebill = explode("_", $_POST['item_id']);
                 if ($rebill[0] == "rebill") {
                     $itemvalue = Expense::find_by_id($rebill[1]);
                     $_POST['name'] = $itemvalue->description;
                     $_POST['type'] = $_POST['item_id'];
                     $_POST['value'] = $itemvalue->value;
                     $itemvalue->rebill = 2;
                     $itemvalue->invoice_id = $_POST['invoice_id'];
                     $itemvalue->save();
                 } else {
                     $itemvalue = Item::find_by_id($_POST['item_id']);
                     $_POST['name'] = $itemvalue->name;
                     $_POST['type'] = $itemvalue->type;
                     $_POST['value'] = $itemvalue->value;
                 }
             }
         }
         $item = InvoiceHasItem::create($_POST);
         if (!$item) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_add_item_success'));
         }
         redirect('invoices/view/' . $_POST['invoice_id']);
     } else {
         $this->view_data['invoice'] = Invoice::find($id);
         $this->view_data['items'] = Item::find('all', array('conditions' => array('inactive=?', '0')));
         $this->view_data['rebill'] = Expense::find('all', array('conditions' => array('project_id=? and (rebill=? or invoice_id=?)', $this->view_data['invoice']->project_id, 1, $id)));
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_add_item');
         $this->view_data['form_action'] = 'invoices/item';
         $this->content_view = 'invoices/_item';
     }
 }
Ejemplo n.º 27
0
 public function receivePayment()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('invoiceID' => 'required|max:50|', 'houseID' => 'required', 'amountdue' => 'required|min:2', 'paymenttype' => 'required', 'amountpayed' => 'required', 'totalpaid' => 'required', 'paymenttyperef' => 'required', 'agent_id' => 'required'));
     if ($v->passes()) {
         $findHouse = Input::get('houseID');
         $propertyId = House::where('name', $findHouse)->pluck('propertyID');
         $propertyName = Property::where('id', $propertyId)->pluck('name');
         $agent_id = Input::get('agent_id');
         $gamount = Input::get('amountdue');
         $gpayed = Input::get('totalpaid');
         $currentPaid = Input::get('amountpayed');
         $initpaid = Input::get('initpaid');
         $cpaid = $gpayed + $currentPaid;
         $agent_id = Input::get('agent_id');
         $billedusr = User::find($agent_id);
         $hisBalance = $billedusr->credit_balance;
         $newBalance = $hisBalance - 3;
         $billedusr->credit_balance = $newBalance;
         $billedusr->save();
         $billstatement = new Statement();
         $billstatement->type = "Receiving Payment";
         $billstatement->amount = 3;
         $billstatement->save();
         $id = Input::get('invoiceID');
         $balance = $gamount - $cpaid;
         $invoice = Invoice::find($id);
         $invoiceid = $invoice->id;
         $invoice->balance = $gamount - $cpaid;
         $invoice->amountpaid = $cpaid;
         $invoice->save();
         // Create a new Receipt
         $reciept = new Receipt();
         $reciept->invoiceID = $invoice->id;
         $reciept->agent_id = $invoice->agent_id;
         $reciept->type = $invoice->type;
         $reciept->houseID = $invoice->houseID;
         $reciept->recipient = $invoice->recipient;
         $reciept->propertyid = $invoice->propertyid;
         $reciept->invoice_amt = $gamount;
         $reciept->amountpaid = $currentPaid;
         $reciept->balance = $gamount - $cpaid;
         $reciept->duedate = $invoice->duedate;
         $reciept->save();
         // Create a new payment report
         $payment = new Payment();
         $payment->invoiceID = Input::get('invoiceID');
         $payment->amount = Input::get('amountdue');
         $payment->amountpayed = Input::get('amountpayed');
         $payment->houseID = $findHouse;
         $payment->client = $invoice->recipient;
         $payment->property = $propertyName;
         $payment->balance = $gamount - $cpaid;
         $payment->paymenttype = Input::get('paymenttype');
         $payment->paymenttyperef = Input::get('paymenttyperef');
         $payment->save();
         #send an sms to the tenant
         $findTenant = $invoice->recipient;
         $ftname = strtok($findTenant, " ");
         $tenants = Tenant::where('name', $ftname)->get();
         foreach ($tenants as $tenant) {
             $t_name = $tenant->name;
             $to = $tenant->phone;
         }
         $message = ' Hi ' . $t_name . ', Your payment of  Ksh. ' . number_format($currentPaid, 2) . ' for ' . $findHouse . '   has been received successfully, due balance ' . number_format($balance, 2) . ', Thank you';
         //	Queue::push('SendSMS', array('message' =>$message ,'number'=>$to ));
         $noteP = array('error' => false, 'message' => 'Payment received successfully');
         return $noteP;
     }
     $notePE = array('error' => true, 'message' => $v->errors()->all());
     return $notePE;
 }
Ejemplo n.º 28
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //return 0;
     // return Response::json(Input::all());
     // $rules = array(
     //           'client' => 'required',
     //           'invoice' => 'required',
     //           'amount' => 'required'
     //       );
     //       if (Input::get('invoice')) {
     //           $invoice = Invoice::scope(Input::get('invoice'))->firstOrFail();
     //           $rules['amount'] .= '|less_than:' . $invoice->balance;
     //       }
     //       if (Input::get('payment_type_id') == PAYMENT_TYPE_CREDIT)
     //       {
     //           $rules['payment_type_id'] = 'has_credit:' . Input::get('client') . ',' . Input::get('amount');
     //       }
     //       $messages = array(
     //     'required' => 'El campo es Requerido',
     //     'positive' => 'El Monto debe ser mayor a cero',
     //     'less_than' => 'El Monto debe ser menor o igual a ' . $invoice->balance,
     //     'has_credit' => 'El Cliente no tiene crédito suficiente'
     // );
     //       $validator = \Validator::make(Input::all(), $rules, $messages);
     //       if ($validator->fails())
     //       {
     //           $url = 'pagos/create';
     //           return Redirect::to($url)
     //               ->withErrors($validator)
     //               ->withInput();
     //       }
     //       else
     //       {
     $payment = Payment::createNew();
     $paymentTypeId = Input::get('payment_type_id');
     $clientId = Input::get('client');
     $amount = floatval(Input::get('amount'));
     // if ($paymentTypeId == PAYMENT_TYPE_CREDIT)
     // {
     //     $credits = Credit::scope()->where('client_id', '=', $clientId)
     //                 ->where('balance', '>', 0)->orderBy('created_at')->get();
     //     $applied = 0;
     //     foreach ($credits as $credit)
     //     {
     //         $applied += $credit->apply($amount);
     //         if ($applied >= $amount)
     //         {
     //             break;
     //         }
     //     }
     // }
     //                $payment->client_id = $clientId;
     //	        $payment->invoice_id =Input::get('invoice');
     //	        $payment->payment_type_id = $paymentTypeId;
     //	       	$payment->user_id = Auth::user()->id;
     //	        $payment->payment_date =  date("Y-m-d",strtotime(Input::get('payment_date')));
     //	        $payment->amount = $amount;
     //	        $payment->transaction_reference = trim(Input::get('transaction_reference'));
     $payment->setClientId($clientId);
     $payment->setInvoiceId(Input::get('invoice'));
     $payment->setPaymentTypeId($paymentTypeId);
     $payment->setUserId(Auth::user()->id);
     $dateparser = explode("/", Input::get('payment_date'));
     $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
     $payment->setPaymentDate($date);
     $payment->setAmount($amount);
     $payment->setTransactionReference(trim(Input::get('transaction_reference')));
     $error = $payment->guardar();
     if ($error) {
         Session::flash('error', $error);
         return Redirect::to('pagos/create');
     }
     $payment->save();
     $cliente = Client::find($payment->client_id);
     $cliente->balance = $cliente->balance - $payment->amount;
     $cliente->paid_to_date = $cliente->paid_to_date + $payment->amount;
     $cliente->save();
     $invoice = Invoice::find($payment->invoice_id);
     $invoice->balance = $invoice->balance - $payment->amount;
     $invoice->save();
     if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
         $credits = Credit::scope()->where('client_id', '=', $clientId)->where('balance', '>', 0)->orderBy('created_at')->get();
         $applied = 0;
         foreach ($credits as $credit) {
             $applied += $credit->apply($amount);
             if ($applied >= $amount) {
                 break;
             }
         }
     }
     $paymentName = PaymentType::where('id', '=', $paymentTypeId)->first();
     if ($invoice->balance == 0) {
         // $invoice->invoice_status_id = INVOICE_STATUS_PAID;
         Utils::addNote($invoice->id, '<b>' . $invoice->getClientName() . ': </b>Totalmente pagada;&nbsp;&nbsp; se pagó:<b>' . $payment->amount . '</b>Bs, con <b>' . $paymentName->name . '</b>', INVOICE_STATUS_PAID);
     } else {
         // $invoice->invoice_status_id = INVOICE_STATUS_PARTIAL;
         Utils::addNote($invoice->id, '<b>' . $invoice->getClientName() . ': </b>Parcialmente pagado;&nbsp;&nbsp; se pagó:<b>' . $payment->amount . '</b> Bs, con <b>' . $paymentName->name . '</b>', INVOICE_STATUS_PARTIAL);
     }
     Session::flash('message', 'Pago creado con éxito');
     $client = Client::where('id', '=', Input::get('client'))->first();
     return Redirect::to('clientes/' . $client->public_id);
     // }
 }
Ejemplo n.º 29
0
 function item_delete($id = FALSE, $estimate_id = FALSE)
 {
     $item = InvoiceHasItem::find($id);
     $invoice = Invoice::find($item->invoice_id);
     $item->delete();
     $this->content_view = 'estimates/view';
     if (!$item) {
         $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_delete_item_error'));
     } else {
         $this->projectlib->updateInvoiceTotal($invoice);
         $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_delete_item_success'));
     }
     redirect('estimates/view/' . $estimate_id);
 }
Ejemplo n.º 30
0
 /**
  * Update the specified resource in storage.
  * PUT /Housedues/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $input = array_except(Input::all(), '_method');
     $v = Validator::make(Input::All(), array('rent' => 'required', 'water' => 'required', 'electricity' => 'required', 'security' => 'required', 'service' => 'required', 'garbage' => 'required', 'duedate' => 'required'));
     if ($v->passes()) {
         $balanceN = Input::get('rent') + Input::get('water') + Input::get('service') + Input::get('garbage') + Input::get('electricity') + Input::get('security');
         $invoice = Invoice::find($id);
         $amountP = $invoice->amountpaid;
         $balance = $balanceN - $amountP;
         $invoice->balance = $balance;
         $invoice->duedate = Input::get('duedate');
         //dd($invoice);
         $invoice->update();
         $invoicedetails = Invoicedetail::where('invoiceID', $id)->first();
         //dd($invoicedetails->toArray());
         $invoicedetails->rent = Input::get('rent');
         $invoicedetails->water = Input::get('water');
         $invoicedetails->garbage = Input::get('garbage');
         $invoicedetails->service = Input::get('service');
         $invoicedetails->electricity = Input::get('electricity');
         $invoicedetails->security = Input::get('security');
         $invoicedetails->update();
         return Redirect::route('admin.invoice.show', $id);
     }
     return Redirect::route('admin.invoice.edit', $id)->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }