Example #1
0
 function saveListItems()
 {
     require_once 'modules/AOS_Products_Quotes/AOS_Products_Quotes.php';
     $productQuote = new AOS_Products_Quotes();
     $product = array('id' => $_POST['product_quote_id'], 'product_id' => $_POST['product_id'], 'product_name' => $_POST['product_name'], 'product_qty' => $_POST['product_qty'], 'vat' => $_POST['vat'], 'vat_amt' => $_POST['vat_amt'], 'product_list_price' => $_POST['product_list_price'], 'product_unit_price' => $_POST['product_unit_price'], 'product_total_price' => $_POST['product_total_price'], 'product_note' => $_POST['product_note'], 'deleted' => $_POST['deleted']);
     $productLineCount = count($product['product_id']);
     for ($i = 0; $i < $productLineCount; $i++) {
         $productQuote->id = $product['id'][$i];
         $productQuote->parent_id = $this->id;
         $productQuote->parent_type = 'AOS_Invoices';
         $productQuote->product_id = $product['product_id'][$i];
         $productQuote->name = $product['product_name'][$i];
         $productQuote->product_qty = $product['product_qty'][$i];
         $productQuote->product_list_price = unformat_number($product['product_list_price'][$i]);
         $productQuote->product_unit_price = unformat_number($product['product_unit_price'][$i]);
         $productQuote->vat = $product['vat'][$i];
         $productQuote->vat_amt = unformat_number($product['vat_amt'][$i]);
         $productQuote->product_total_price = unformat_number($product['product_total_price'][$i]);
         $productQuote->description = $product['product_note'][$i];
         $productQuote->deleted = $product['deleted'][$i];
         if ($productQuote->deleted == 1) {
             $productQuote->mark_deleted($productQuote->id);
         } else {
             if (trim($productQuote->product_id) != '') {
                 $productQuote->save();
             }
         }
     }
 }
 function save_lines($post_data, $parent, $groups = array(), $key = '')
 {
     $line_count = count($post_data[$key . 'name']);
     $j = 0;
     for ($i = 0; $i < $line_count; ++$i) {
         if ($post_data[$key . 'deleted'][$i] == 1) {
             $this->mark_deleted($post_data[$key . 'id'][$i]);
         } else {
             $product_quote = new AOS_Products_Quotes();
             foreach ($this->field_defs as $field_def) {
                 if (isset($post_data[$key . $field_def['name']][$i])) {
                     $product_quote->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i];
                 }
             }
             if (isset($post_data[$key . 'group_number'][$i])) {
                 $product_quote->group_id = $groups[$post_data[$key . 'group_number'][$i]];
             }
             if (trim($product_quote->product_id) != '' && trim($product_quote->name) != '' && trim($product_quote->product_unit_price) != '') {
                 $product_quote->number = ++$j;
                 $product_quote->assigned_user_id = $parent->assigned_user_id;
                 $product_quote->parent_id = $parent->id;
                 $product_quote->currency_id = $parent->currency_id;
                 $product_quote->parent_type = $parent->object_name;
                 $product_quote->save();
             }
         }
     }
 }
 public function testsave()
 {
     $aosProductsQuotes = new AOS_Products_Quotes();
     $aosProductsQuotes->name = 'test';
     $aosProductsQuotes->product_id = 1;
     $aosProductsQuotes->product_unit_price = 100;
     $aosProductsQuotes->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($aosProductsQuotes->id));
     $this->assertEquals(36, strlen($aosProductsQuotes->id));
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $aosProductsQuotes->mark_deleted($aosProductsQuotes->id);
     $result = $aosProductsQuotes->retrieve($aosProductsQuotes->id);
     $this->assertEquals(null, $result);
 }
Example #4
0
$result = $this->bean->db->query($sql);
while ($row = $this->bean->db->fetchByAssoc($result)) {
    $row['id'] = '';
    $row['parent_id'] = $contract->id;
    $row['parent_type'] = 'AOS_Contracts';
    if ($row['product_cost_price'] != null) {
        $row['product_cost_price'] = format_number($row['product_cost_price']);
    }
    $row['product_list_price'] = format_number($row['product_list_price']);
    if ($row['product_discount'] != null) {
        $row['product_discount'] = format_number($row['product_discount']);
        $row['product_discount_amount'] = format_number($row['product_discount_amount']);
    }
    $row['product_unit_price'] = format_number($row['product_unit_price']);
    $row['vat_amt'] = format_number($row['vat_amt']);
    $row['product_total_price'] = format_number($row['product_total_price']);
    $row['product_qty'] = format_number($row['product_qty']);
    $row['group_id'] = $group_id_map[$row['group_id']];
    $prod_contract = new AOS_Products_Quotes();
    $prod_contract->populateFromRow($row);
    $prod_contract->save();
}
//Setting contract quote relationship
require_once 'modules/Relationships/Relationship.php';
$key = Relationship::retrieve_by_modules('AOS_Quotes', 'AOS_Contracts', $GLOBALS['db']);
if (!empty($key)) {
    $quote->load_relationship($key);
    $quote->{$key}->add($contract->id);
}
ob_clean();
header('Location: index.php?module=AOS_Contracts&action=EditView&record=' . $contract->id);
 function mark_deleted($id)
 {
     $recordId = $this->id;
     $productQuote = new AOS_Products_Quotes();
     $sql = "SELECT id FROM aos_products_quotes WHERE parent_type = 'AOS_Invoices' AND parent_id = '" . $recordId . "' AND deleted = 0";
     $result = $this->db->query($sql);
     parent::mark_deleted($id);
     while ($row = $this->db->fetchByAssoc($result)) {
         $productQuote->id = $row['id'];
         $productQuote->parent_id = $recordId;
         $productQuote->save();
         $productQuote->mark_deleted($row['id']);
     }
 }
require_once 'modules/Relationships/Relationship.php';
$key = Relationship::retrieve_by_modules('AOS_Quotes', 'AOS_Invoices', $GLOBALS['db']);
if (!empty($key)) {
    $quote->load_relationship($key);
    $quote->{$key}->add($invoice->id);
}
//Setting Line Items
$sql = "SELECT * FROM aos_products_quotes WHERE parent_type = 'AOS_Quotes' AND parent_id = '" . $quote->id . "' AND deleted = 0";
$result = $this->bean->db->query($sql);
while ($row = $this->bean->db->fetchByAssoc($result)) {
    $row['id'] = '';
    $row['parent_id'] = $invoice->id;
    $row['parent_type'] = 'AOS_Invoices';
    if ($row['product_cost_price'] != null) {
        $row['product_cost_price'] = format_number($row['product_cost_price']);
    }
    $row['product_list_price'] = format_number($row['product_list_price']);
    if ($row['product_discount'] != null) {
        $row['product_discount'] = format_number($row['product_discount']);
        $row['product_discount_amount'] = format_number($row['product_discount_amount']);
    }
    $row['product_unit_price'] = format_number($row['product_unit_price']);
    $row['vat_amt'] = format_number($row['vat_amt']);
    $row['product_total_price'] = format_number($row['product_total_price']);
    $row['product_qty'] = format_number($row['product_qty']);
    $prod_invoice = new AOS_Products_Quotes();
    $prod_invoice->populateFromRow($row);
    $prod_invoice->save();
}
ob_clean();
header('Location: index.php?module=AOS_Invoices&action=EditView&record=' . $invoice->id);