Example #1
0
 function order()
 {
     if ($this->state >= org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED) {
         return false;
     }
     // Cache the original cost values intended and reset the fields
     $this->plannedUnits = $this->units;
     $this->plannedCost = $this->cost;
     if ($this->invoiceByActualUnits) {
         $this->cost = 0;
         $this->units = 0;
     }
     // Check what kind of order this is
     $product = org_openpsa_products_product_dba::get_cached($this->product);
     $scheduler = new org_openpsa_invoices_scheduler($this);
     if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
         // This is a new subscription, initiate the cycle but don't send invoice
         if (!$scheduler->run_cycle(1, false)) {
             return false;
         }
     } else {
         // Check if we need to create task or ship goods
         switch ($product->orgOpenpsaObtype) {
             case org_openpsa_products_product_dba::TYPE_SERVICE:
                 $scheduler->create_task($this->start, $this->end, $this->title);
                 break;
             case org_openpsa_products_product_dba::TYPE_GOODS:
                 // TODO: Warehouse management: create new order
             // TODO: Warehouse management: create new order
             default:
                 break;
         }
     }
     $this->state = org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED;
     if ($this->update()) {
         // Update sales project and mark as won
         $salesproject = new org_openpsa_sales_salesproject_dba($this->salesproject);
         if ($salesproject->status != org_openpsa_sales_salesproject_dba::STATUS_WON) {
             $salesproject->status = org_openpsa_sales_salesproject_dba::STATUS_WON;
             $salesproject->update();
         }
         return true;
     }
     return false;
 }