예제 #1
0
 /**
  */
 public function process_deliverable(org_openpsa_sales_salesproject_deliverable_dba $deliverable, $cycle_number = null)
 {
     $this->_deliverable = $deliverable;
     // Recalculate price to catch possible unit changes
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.sales', 'config')->get('calculator');
     $client = new $client_class();
     $client->run($this->_deliverable);
     $this_cycle_amount = $client->get_price();
     if ($this_cycle_amount == 0) {
         debug_add('Invoice sum 0, skipping invoice creation');
         return 0;
     }
     $this->_invoice = $this->_probe_invoice($cycle_number);
     if (!$this->_invoice->update()) {
         throw new midcom_error("The invoice could not be saved. Last Midgard error was: " . midcom_connection::get_error_string());
     }
     // TODO: Create invoicing task if assignee is defined
     $items = $client->get_invoice_items($this->_invoice);
     foreach ($items as $item) {
         $item->deliverable = $this->_deliverable->id;
         $item->skip_invoice_update = true;
         if ($item->id) {
             $stat = $item->update();
         } else {
             $stat = $item->create();
         }
         if (!$stat) {
             throw new midcom_error('Failed to save item to disk, ' . midcom_connection::get_error_string());
         }
     }
     org_openpsa_invoices_invoice_item_dba::update_invoice($this->_invoice);
     org_openpsa_invoices_invoice_item_dba::update_deliverable($this->_deliverable);
     return $this_cycle_amount;
 }
예제 #2
0
파일: pdf.php 프로젝트: nemein/openpsa
 public static function render_and_attach_pdf(org_openpsa_invoices_invoice_dba $invoice)
 {
     if ($invoice->date == 0 || $invoice->deliverydate == 0) {
         $time = time();
         if ($invoice->date == 0) {
             $invoice->date = $time;
         }
         if ($invoice->deliverydate == 0) {
             $invoice->deliverydate = $time;
         }
         $invoice->update();
     }
     // renders the pdf and attaches it to the invoice
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
     if (!class_exists($client_class)) {
         debug_add('Could not find PDF renderer, aborting silently', MIDCOM_LOG_INFO);
         return false;
     }
     $pdf_builder = new $client_class($invoice);
     // tmp filename
     $tmp_dir = $GLOBALS["midcom_config"]["midcom_tempdir"];
     $title = str_replace("#", "", $invoice->get_label());
     $tmp_file = $tmp_dir . "/" . $title . ".pdf";
     // render pdf to tmp filename
     $render = $pdf_builder->render($tmp_file);
     // cleanup old attachments
     $pdf_files = org_openpsa_helpers::get_attachment_urls($invoice, "pdf_file");
     if (count($pdf_files) > 0) {
         foreach ($pdf_files as $guid => $url) {
             $attachment = new midcom_db_attachment($guid);
             $attachment->delete();
         }
     }
     $attachment = $invoice->create_attachment($title . '.pdf', $title, "application/pdf");
     if (!$attachment) {
         debug_add("Failed to create invoice attachment for pdf", MIDCOM_LOG_ERROR);
         return false;
     }
     $copy = $attachment->copy_from_file($tmp_file);
     if (!$copy) {
         debug_add("Failed to copy pdf from " . $tmp_file . " to attachment", MIDCOM_LOG_ERROR);
         return false;
     }
     // set parameter for datamanager to find the pdf
     if (!$invoice->set_parameter("midcom.helper.datamanager2.type.blobs", "guids_pdf_file", $attachment->guid . ":" . $attachment->guid) || !$attachment->set_parameter('org.openpsa.invoices', 'auto_generated', md5_file($tmp_file))) {
         debug_add("Failed to create attachment parameters, last midgard error was: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
         return false;
     }
     return true;
 }
예제 #3
0
파일: action.php 프로젝트: nemein/openpsa
 /**
  * helper function - contains code to mark invoice as sent,
  * maybe move it to invoice-class ?
  *
  * @param org_openpsa_invoices_invoice_dba $invoice contains invoice
  */
 private function _mark_as_sent(org_openpsa_invoices_invoice_dba $invoice)
 {
     if (!$invoice->sent) {
         $invoice->sent = time();
         if ($invoice->update()) {
             $this->_request_data['message']['message'] = sprintf($this->_l10n->get('marked invoice %s sent'), $invoice->get_label());
         } else {
             $this->_request_data['message']['message'] = sprintf($this->_l10n->get('could not mark invoice %s paid'), $invoice->get_label());
             return false;
         }
         $mc = new org_openpsa_relatedto_collector($invoice->guid, 'org_openpsa_projects_task_dba');
         $tasks = $mc->get_related_objects();
         // Close "Send invoice" task
         foreach ($tasks as $task) {
             if (org_openpsa_projects_workflow::complete($task) && !isset($args["no_redirect"])) {
                 midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.invoices'), sprintf($this->_l10n->get('marked task "%s" finished'), $task->title), 'ok');
             }
         }
     }
     return true;
 }
예제 #4
0
파일: item.php 프로젝트: nemein/openpsa
 public static function update_invoice(org_openpsa_invoices_invoice_dba $invoice)
 {
     $invoice_sum = self::get_sum(array('invoice' => $invoice->id));
     $invoice_sum = round($invoice_sum, 2);
     if ($invoice_sum != round($invoice->sum, 2)) {
         $invoice->sum = $invoice_sum;
         $invoice->update();
     }
 }