예제 #1
0
 function item($condition = FALSE, $item_id = FALSE)
 {
     switch ($condition) {
         case 'view':
         default:
             //$this->theme_view = 'modal';
             $this->content_view = 'invoices/client_views/item_view';
             $this->view_data['title'] = $this->lang->line('application_item_details');
             $this->view_data['item'] = InvoiceHasItem::find($item_id);
             break;
     }
 }
예제 #2
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);
 }
예제 #3
0
 function item_delete($id = FALSE, $estimate_id = FALSE)
 {
     $item = InvoiceHasItem::find($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->session->set_flashdata('message', 'success:' . $this->lang->line('messages_delete_item_success'));
     }
     redirect('estimates/view/' . $estimate_id);
 }
예제 #4
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);
 }
예제 #5
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";
     }
 }
 function create_invoice($id = FALSE)
 {
     $subscription = Subscription::find($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('+14 day', strtotime($subscription->next_payment)));
         $_POST['currency'] = $subscription->currency;
         $_POST['terms'] = $subscription->terms;
         $_POST['discount'] = $subscription->discount;
         $_POST['tax'] = $subscription->tax;
         $_POST['second_tax'] = $subscription->second_tax;
         $_POST['reference'] = $invoice_reference->invoice_reference;
         $invoice = Invoice::create($_POST);
         $invoiceid = Invoice::last();
         $items = SubscriptionHasItem::find('all', array('conditions' => array('subscription_id=?', $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) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_invoice_error'));
         } else {
             $subscription->next_payment = date('Y-m-d', strtotime($subscription->frequency, strtotime($subscription->next_payment)));
             $subscription->save();
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_invoice_success'));
         }
         redirect('subscriptions/view/' . $id);
     }
 }
예제 #7
0
 function planOrder($id = FALSE, $condition = FALSE, $plan_id = FALSE)
 {
     $this->load->helper('notification');
     $this->view_data['submenu'] = array($this->lang->line('application_back') => 'cprojects', $this->lang->line('application_overview') => 'cprojects/view/' . $id, $this->lang->line('application_tasks') => 'cprojects/tasks/' . $id, $this->lang->line('application_media') => 'cprojects/media/' . $id);
     switch ($condition) {
         case 'create':
             $plan = ProjectHasItem::find($plan_id);
             $current_inventory = $plan->shipping_available_inventory;
             if ($_POST) {
                 if (!isset($plan_id) || empty($plan_id)) {
                     $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_item_empty'));
                     redirect('cprojects/view/' . $id);
                 }
                 if (!$current_inventory) {
                     $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_inventory_empty'));
                     redirect('cprojects/view/' . $id);
                 }
                 $quantity = $_POST['amount'];
                 $current_inventory_available = $current_inventory - $quantity;
                 if (!$quantity) {
                     $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_qty_empty'));
                     redirect('cprojects/view/' . $id);
                 }
                 if ($current_inventory_available < 0) {
                     $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_qty_empty'));
                     redirect('cprojects/view/' . $id);
                 }
                 unset($_POST['send']);
                 unset($_POST['files']);
                 unset($_POST['amount']);
                 $_POST['shipping_lebel'] = '';
                 $config['upload_path'] = './files/media';
                 $config['encrypt_name'] = TRUE;
                 $config['allowed_types'] = '*';
                 $this->load->library('upload', $config);
                 if ($this->upload->do_upload()) {
                     $data = array('upload_data' => $this->upload->data());
                     $_POST['shipping_lebel'] = $data['upload_data']['file_name'];
                 }
                 unset($_POST['userfile']);
                 unset($_POST['dummy']);
                 $_POST = array_map('htmlspecialchars', $_POST);
                 $shipping_address = array('shipping_name' => $_POST['shipping_name'], 'shipping_company' => $_POST['shipping_company'], 'shipping_address' => $_POST['shipping_address'], 'shipping_city' => $_POST['shipping_city'], 'shipping_state' => $_POST['shipping_state'], 'shipping_zip' => $_POST['shipping_zip'], 'shipping_country' => $_POST['shipping_country'], 'shipping_phone' => $_POST['shipping_phone'], 'shipping_email' => $_POST['shipping_email'], 'shipping_website' => $_POST['shipping_website']);
                 unset($_POST['shipping_name']);
                 unset($_POST['shipping_company']);
                 unset($_POST['shipping_address']);
                 unset($_POST['shipping_city']);
                 unset($_POST['shipping_state']);
                 unset($_POST['shipping_zip']);
                 unset($_POST['shipping_country']);
                 unset($_POST['shipping_phone']);
                 unset($_POST['shipping_email']);
                 unset($_POST['shipping_website']);
                 $core_settings = Setting::first();
                 $_POST['reference'] = $core_settings->invoice_reference;
                 $_POST['project_id'] = $id;
                 $_POST['company_id'] = $this->client->company->id;
                 $_POST['status'] = 'Sent';
                 $_POST['issue_date'] = date('Y-m-d');
                 $_POST['due_date'] = date('Y-m-d', strtotime('+1 day'));
                 $_POST['currency'] = $core_settings->currency;
                 $_POST['terms'] = $core_settings->invoice_terms;
                 $_POST['invoice_type'] = $this->invoice_shipment_type;
                 $invoice = Invoice::create($_POST);
                 $new_invoice_reference = $_POST['reference'] + 1;
                 $invoice_id = $invoice->id;
                 $this->projectlib->addInvoiceAddress($invoice_id, true, $shipping_address);
                 $invoice_reference = Setting::first();
                 $invoice_reference->update_attributes(array('invoice_reference' => $new_invoice_reference));
                 $invoice_item_data = array('invoice_id' => $invoice_id, 'item_id' => $plan->item_id, 'project_item_id' => $plan->id, 'photo' => $plan->photo, 'photo_type' => $plan->photo_type, 'photo_original_name' => $plan->photo_original_name, 'name' => $plan->name, 'amount' => $quantity, 'type' => $plan->type, 'description' => $plan->description, 'sku' => $plan->sku, 'value' => $plan->cost, 'original_cost' => $plan->original_cost, 'shipping_item' => '1', 'shipping_method' => $plan->shipping_method, 'shipping_box_size_length' => $plan->shipping_box_size_length, 'shipping_box_size_width' => $plan->shipping_box_size_width, 'shipping_box_size_height' => $plan->shipping_box_size_height, 'shipping_box_size_weight' => $plan->shipping_box_size_weight, 'shipping_pcs_in_carton' => $plan->shipping_pcs_in_carton);
                 $item_add = InvoiceHasItem::create($invoice_item_data);
                 $plan->shipping_available_inventory = $current_inventory_available;
                 if (!$current_inventory_available) {
                     $plan->payment_status = 'invoiced';
                 }
                 $plan->save();
                 $this->projectlib->updateInvoiceTotal($invoice);
                 $this->projectlib->sendInvoice($invoice_id, false);
                 if (!$invoice) {
                     $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_invoice_error'));
                 } else {
                     $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_invoice_success'));
                 }
                 redirect('cinvoices/view/' . $invoice_id);
             } else {
                 $this->load->library('geolib');
                 $this->view_data['geolib'] = $this->geolib;
                 $this->view_data['max_qty'] = $plan->shipping_available_inventory;
                 $this->theme_view = 'modal';
                 $this->view_data['title'] = $this->lang->line('application_create_shipping_plan');
                 $this->view_data['form_action'] = 'cprojects/planOrder/' . $id . '/create/' . $plan_id;
                 $this->content_view = 'projects/client_views/_create_plan';
             }
             break;
         default:
             $this->view_data['project'] = Project::find($id);
             $this->content_view = 'cprojects/view/' . $id;
             break;
     }
 }
예제 #8
0
 public function sendInvoice($id = FALSE, $redirect = true)
 {
     $this->_ci->load->helper(array('dompdf', 'file'));
     $this->_ci->load->library('parser');
     $data["invoice"] = 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["invoice"]->due_date . ' 00:00:00'));
     //Set parse values
     $parse_data = array('client_contact' => $data["invoice"]->company->client->firstname . ' ' . $data["invoice"]->company->client->lastname, 'client_company' => $data["invoice"]->company->name, '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 . '"/>');
     // Generate PDF
     $html = $this->_ci->load->view($data["core_settings"]->template . '/' . $data["core_settings"]->invoice_pdf_template, $data, true);
     $html = $this->_ci->parser->parse_string($html, $parse_data);
     $filename = $this->_ci->lang->line('application_invoice') . '_' . $data["invoice"]->reference;
     pdf_create($html, $filename, FALSE);
     //email
     $subject = $this->_ci->parser->parse_string($data["core_settings"]->invoice_mail_subject, $parse_data);
     $this->_ci->email->from($data["core_settings"]->email, $data["core_settings"]->company);
     if (!isset($data["invoice"]->company->client->email)) {
         $this->_ci->session->set_flashdata('message', 'error:This client company has no primary contact! Just add a primary contact.');
         if ($redirect) {
             redirect('invoices/view/' . $id);
         }
     }
     $this->_ci->email->to($data["invoice"]->company->client->email);
     $this->_ci->email->subject($subject);
     $this->_ci->email->attach("files/temp/" . $filename . ".pdf");
     $email_invoice = read_file('./application/views/' . $data["core_settings"]->template . '/templates/email_invoice.html');
     $message = $this->_ci->parser->parse_string($email_invoice, $parse_data);
     $this->_ci->email->message($message);
     if ($this->_ci->email->send()) {
         $this->_ci->session->set_flashdata('message', 'success:' . $this->_ci->lang->line('messages_send_invoice_success'));
         $data["invoice"]->update_attributes(array('status' => 'Sent', 'sent_date' => date("Y-m-d")));
         log_message('error', 'Invoice #' . $data["invoice"]->reference . ' has been send to ' . $data["invoice"]->company->client->email);
     } else {
         $this->_ci->session->set_flashdata('message', 'error:' . $this->_ci->lang->line('messages_send_invoice_error'));
         log_message('error', 'ERROR: Invoice #' . $data["invoice"]->reference . ' has not been send to ' . $data["invoice"]->company->client->email . '. Please check your servers email settings.');
     }
     unlink("files/temp/" . $filename . ".pdf");
     if ($redirect) {
         redirect('invoices/view/' . $id);
     }
 }