Exemple #1
0
 public function gerateBilling()
 {
     $order = null;
     $customers = $this->getUserID();
     $structJsonArray = array();
     foreach ($customers as $customer) {
         $structJson = new Json();
         $structJson->setCustomerId($customer['zoho_books_contact_id']);
         $structJson->setDate(date('d-m-Y'));
         $invoices_per_costumer = $this->getUserInvoice($customer['zoho_books_contact_id']);
         //var_dump($invoices_per_costumer);
         foreach ($invoices_per_costumer as $invoice_each) {
             $item = new Item();
             $order++;
             $item->setItemId("460000000027017");
             $item->setProjectId("");
             $item->setExpenseId("");
             $item->setName("Print Services");
             $item->setDescription($invoice_each['description']);
             $item->setItemOrder($order);
             $item->setRate($invoice_each['rate']);
             $item->setUnit("Nos");
             $item->setQuantity(1.0);
             $item->setDiscount(0.0);
             $item->setTaxId("460000000027005");
             $structJson->setLineItems($item);
             $item = null;
         }
         $structJson->setNotes("Thanks for your business.");
         $order = null;
         $structJsonArray[] = $structJson;
         $structJson = null;
     }
     return $structJsonArray;
 }
 /**
  * Receives the Invoice form data and calculates each row total amount and
  * full invoice totals. Returns a json
  *
  * @param 'invoice' from Request
  * @return JSON through Response
  */
 public function executeCalculate(sfWebRequest $request)
 {
     $currency = PropertyTable::get('currency');
     $format = new sfNumberFormat($this->culture);
     $data = $request->getParameter('invoice');
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     $invoice = new Invoice();
     $items = array();
     $totals = array();
     if (isset($data['Items'])) {
         foreach ((array) $data['Items'] as $itemId => $itemData) {
             if ($itemData['remove']) {
                 continue;
             }
             $item = new Item();
             $item->setUnitaryCost($itemData['unitary_cost']);
             $item->setQuantity($itemData['quantity']);
             $item->setDiscount($itemData['discount']);
             if (isset($itemData['taxes_list'])) {
                 $taxes = Doctrine::getTable('Tax')->createQuery()->whereIn('id', $itemData['taxes_list'])->execute();
                 $item->Taxes = $taxes;
             }
             $items[$itemId] = $format->format($item->getGrossAmount(), 'c', $currency);
             $invoice->Items[] = $item;
         }
         $totals['base'] = $format->format($invoice->calculate('base_amount', true), 'c', $currency);
         $totals['discount'] = $format->format($invoice->calculate('discount_amount', true), 'c', $currency);
         $totals['net'] = $format->format($invoice->calculate('net_amount', true), 'c', $currency);
         $totals['taxes'] = $format->format($invoice->calculate('tax_amount', true), 'c', $currency);
         $totals['gross'] = $format->format($invoice->calculate('gross_amount', true), 'c', $currency);
     } else {
         $zero = $format->format(0, 'c', $currency);
         $totals['base'] = $zero;
         $totals['discount'] = $zero;
         $totals['net'] = $zero;
         $totals['taxes'] = $zero;
         $totals['gross'] = $zero;
     }
     return $this->renderText(json_encode(array('items' => $items, 'totals' => $totals)));
 }
Exemple #3
0
 /**
  * @param array $data
  */
 public function setItemsByData($data)
 {
     foreach ($data as $itemData) {
         $item = new Item();
         if (isset($itemData['item'])) {
             $itemData = array_merge($itemData, $itemData['item']);
         }
         // stop if quantity is smaller than 0
         if ($this->getProperty('quantity', $itemData, 0) < 1) {
             continue;
         }
         $item->setPrice($this->getProperty('price', $itemData, 0));
         $item->setQuantity($this->getProperty('quantity', $itemData));
         $item->setQuantityUnit($this->getProperty('quantityUnit', $itemData));
         $item->setAddress($this->getProperty('address', $itemData));
         $item->setUseProductsPrice($this->getProperty('useProductsPrice', $itemData));
         $item->setDeliveryDate($this->getProperty('deliveryDate', $itemData));
         $item->setNetShippingCosts($this->getProperty('netShippingCosts', $itemData));
         if (isset($itemData['product'])) {
             $product = new Product($this->getProperty('id', $itemData['product']));
             $item->setProduct($product);
         }
         // set account to customer
         if (isset($itemData['account']) && !isset($itemData['customer'])) {
             $itemData['customer'] = $itemData['account'];
         }
         if (isset($itemData['customer'])) {
             $customer = new Account($this->getProperty('id', $itemData['customer']), $this->getProperty('name', $itemData['customer']));
             $item->setCustomerAccount($customer);
         }
         if (isset($itemData['supplier'])) {
             $customer = new Account($this->getProperty('id', $itemData['supplier']), $this->getProperty('name', $itemData['supplier']));
             $item->setSupplierAccount($customer);
         }
         // add to items array
         $this->items[] = $item;
         // create ordered item arrays
         $customerId = 0;
         $supplierId = 0;
         if ($item->getCustomerAccount()) {
             $customerId = $item->getCustomerAccount()->getId();
         }
         if ($item->getSupplierAccount()) {
             $supplierId = $item->getSupplierAccount()->getId();
         }
         $this->customerItems[$customerId][] = $item;
         $this->customerSupplierItems[$customerId]['supplierItems'][$supplierId][] = $item;
     }
 }
 protected function generateInvoiceItems()
 {
     for ($j = 0; $j < mt_rand(1, 10); $j++) {
         $item = new Item();
         $item->setDescription($this->items[array_rand($this->items)]);
         $item->setUnitaryCost(mt_rand(100, 100000) / 100);
         $item->setQuantity(mt_rand(1, 10));
         if (mt_rand(1, 15) == 1) {
             $item->setDiscount(mt_rand(1, 70));
         }
         $max_tax = mt_rand(1, 10) == 1 ? mt_rand(1, 3) : 1;
         for ($kk = 0; $kk < $max_tax; $kk++) {
             $item->Taxes[] = $this->getRandomTax();
         }
         $this->inv->Items[] = $item;
     }
 }
 /**
  * Adds a new product/item in this payment request
  * 
  * @param String $id
  * @param String $description
  * @param String $quantity
  * @param String $amount
  * @param String $weight
  * @param String $shippingCost
  */
 public function addItem($id, $description = null, $quantity = null, $amount = null, $weight = null, $shippingCost = null)
 {
     $param = $id;
     if ($this->items == null) {
         $this->items = array();
     }
     if (is_array($param)) {
         array_push($this->items, new Item($param));
     } else {
         if ($param instanceof Item) {
             array_push($this->items, $param);
         } else {
             $item = new Item();
             $item->setId($param);
             $item->setDescription($description);
             $item->setQuantity($quantity);
             $item->setAmount($amount);
             $item->setWeight($weight);
             $item->setShippingCost($shippingCost);
             array_push($this->items, $item);
         }
     }
 }
 private static function parseTransactionItem($data)
 {
     // <transaction> <items> <item>
     $item = new Item();
     // <transaction> <items> <item> <id>
     if (isset($data["id"])) {
         $item->setId($data["id"]);
     }
     // <transaction> <items> <item> <description>
     if (isset($data["description"])) {
         $item->setDescription($data["description"]);
     }
     // <transaction> <items> <item> <quantity>
     if (isset($data["quantity"])) {
         $item->setQuantity($data["quantity"]);
     }
     // <transaction> <items> <item> <amount>
     if (isset($data["amount"])) {
         $item->setAmount($data["amount"]);
     }
     // <transaction> <items> <item> <weight>
     if (isset($data["weight"])) {
         $item->setWeight($data["weight"]);
     }
     return $item;
 }
Exemple #7
0
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(6, new lime_output_color());
$t->diag('Item class tests');
$item = new Item();
$item->setUnitaryCost(1234.214);
$item->setQuantity(3);
$item->setDiscount(13);
$tax1 = new Tax();
$tax2 = new Tax();
$tax1->setValue(16);
$tax2->setValue(4);
$item->Taxes[] = $tax1;
$item->Taxes[] = $tax2;
$base = 1234.214 * 3;
$discount = $base * 13 / 100;
$taxAmount = ($base - $discount) * ($tax1->value + $tax2->value) / 100;
$t->is($item->getBaseAmount(), $base, 'getBaseAmount()');
$t->is($item->getNetAmount(), $base - $discount, 'getNetAmount()');
$t->is($item->getDiscountAmount(), $discount, 'getDiscountAmount()');
$t->is($item->getTaxAmount(), $taxAmount, 'getTaxAmount()');
$t->is($item->getGrossAmount(), $base - $discount + $taxAmount, 'getGrossAmount()');
$t->is($item->getTaxesPercent(), $tax1->value + $tax2->value, 'getTaxesPercent()');