예제 #1
0
 function save_groups($post_data, $parent, $key = '')
 {
     $groups = array();
     $group_count = count($post_data[$key . 'group_number']);
     $j = 0;
     for ($i = 0; $i < $group_count; ++$i) {
         if ($post_data[$key . 'deleted'][$i] == 1) {
             $this->mark_deleted($post_data[$key . 'id'][$i]);
         } else {
             $product_quote_group = new AOS_Line_Item_Groups();
             foreach ($this->field_defs as $field_def) {
                 if (isset($post_data[$key . $field_def['name']][$i])) {
                     $product_quote_group->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i];
                 }
             }
             $product_quote_group->number = ++$j;
             $product_quote_group->assigned_user_id = $parent->assigned_user_id;
             $product_quote_group->currency_id = $parent->currency_id;
             $product_quote_group->parent_id = $parent->id;
             $product_quote_group->parent_type = $parent->object_name;
             $product_quote_group->save();
             if (isset($post_data[$key . 'group_number'][$i])) {
                 $groups[$post_data[$key . 'group_number'][$i]] = $product_quote_group->id;
             }
         }
     }
     require_once 'modules/AOS_Products_Quotes/AOS_Products_Quotes.php';
     $productQuote = new AOS_Products_Quotes();
     $productQuote->save_lines($post_data, $parent, $groups, 'product_');
     $productQuote->save_lines($post_data, $parent, $groups, 'service_');
 }
예제 #2
0
 function save($check_notify = FALSE)
 {
     global $sugar_config;
     if (empty($this->id) || $this->new_with_id) {
         if (isset($_POST['group_id'])) {
             unset($_POST['group_id']);
         }
         if (isset($_POST['product_id'])) {
             unset($_POST['product_id']);
         }
         if (isset($_POST['service_id'])) {
             unset($_POST['service_id']);
         }
         if ($sugar_config['dbconfig']['db_type'] == 'mssql') {
             $this->number = $this->db->getOne("SELECT MAX(CAST(number as INT))+1 FROM aos_quotes");
         } else {
             $this->number = $this->db->getOne("SELECT MAX(CAST(number as UNSIGNED))+1 FROM aos_quotes");
         }
         if ($this->number < $sugar_config['aos']['quotes']['initialNumber']) {
             $this->number = $sugar_config['aos']['quotes']['initialNumber'];
         }
     }
     require_once 'modules/AOS_Products_Quotes/AOS_Utils.php';
     perform_aos_save($this);
     parent::save($check_notify);
     require_once 'modules/AOS_Line_Item_Groups/AOS_Line_Item_Groups.php';
     $productQuoteGroup = new AOS_Line_Item_Groups();
     $productQuoteGroup->save_groups($_POST, $this, 'group_');
 }
 public function testsave()
 {
     $aosLineItemGroup = new AOS_Line_Item_Groups();
     $aosLineItemGroup->name = 'test';
     $aosLineItemGroup->total_amount = 100;
     $aosLineItemGroup->total_amount_usdollar = 100;
     $aosLineItemGroup->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($aosLineItemGroup->id));
     $this->assertEquals(36, strlen($aosLineItemGroup->id));
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $aosLineItemGroup->mark_deleted($aosLineItemGroup->id);
     $result = $aosLineItemGroup->retrieve($aosLineItemGroup->id);
     $this->assertEquals(null, $result);
 }
예제 #4
0
 function save($check_notify = FALSE)
 {
     if (empty($this->id)) {
         unset($_POST['group_id']);
         unset($_POST['product_id']);
         unset($_POST['service_id']);
     }
     if (isset($_POST['renewal_reminder_date']) && !empty($_POST['renewal_reminder_date'])) {
         $this->createReminder();
     }
     parent::save($check_notify);
     require_once 'modules/AOS_Line_Item_Groups/AOS_Line_Item_Groups.php';
     $productQuoteGroup = new AOS_Line_Item_Groups();
     $productQuoteGroup->save_groups($_POST, $this, 'group_');
     if (isset($_POST['renewal_reminder_date']) && !empty($_POST['renewal_reminder_date'])) {
         $this->createLink();
     }
 }
예제 #5
0
    if ($row['discount_amount'] != null) {
        $row['discount_amount'] = format_number($row['discount_amount']);
    }
    if ($row['subtotal_amount'] != null) {
        $row['subtotal_amount'] = format_number($row['subtotal_amount']);
    }
    if ($row['tax_amount'] != null) {
        $row['tax_amount'] = format_number($row['tax_amount']);
    }
    if ($row['subtotal_tax_amount'] != null) {
        $row['subtotal_tax_amount'] = format_number($row['subtotal_tax_amount']);
    }
    if ($row['total_amount'] != null) {
        $row['total_amount'] = format_number($row['total_amount']);
    }
    $group_contract = new AOS_Line_Item_Groups();
    $group_contract->populateFromRow($row);
    $group_contract->save();
    $group_id_map[$old_id] = $group_contract->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'] = $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']);
예제 #6
0
/**
 * Advanced OpenSales, Advanced, robust set of sales modules.
 * @package Advanced OpenSales for SugarCRM
 * @copyright SalesAgility Ltd http://www.salesagility.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 * along with this program; if not, see http://www.gnu.org/licenses
 * or write to the Free Software Foundation,Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301  USA
 *
 * @author SalesAgility <*****@*****.**>
 */
function display_lines($focus, $field, $value, $view)
{
    global $sugar_config, $locale, $app_list_strings, $mod_strings;
    $enable_groups = (int) $sugar_config['aos']['lineItems']['enableGroups'];
    $total_tax = (int) $sugar_config['aos']['lineItems']['totalTax'];
    $html = '';
    if ($view == 'EditView') {
        $html .= '<script src="modules/AOS_Products_Quotes/line_items.js"></script>';
        if (file_exists('custom/modules/AOS_Products_Quotes/line_items.js')) {
            $html .= '<script src="custom/modules/AOS_Products_Quotes/line_items.js"></script>';
        }
        $html .= '<script language="javascript">var sig_digits = ' . $locale->getPrecision() . ';';
        $html .= 'var module_sugar_grp1 = "' . $focus->module_dir . '";';
        $html .= 'var enable_groups = ' . $enable_groups . ';';
        $html .= 'var total_tax = ' . $total_tax . ';';
        $html .= '</script>';
        $html .= "<table border='0' cellspacing='4' width='37.5%' id='lineItems'></table>";
        if ($enable_groups) {
            $html .= "<div style='padding-top: 10px; padding-bottom:10px;'>";
            $html .= "<input type=\"button\" tabindex=\"116\" class=\"button\" value=\"" . $mod_strings['LBL_ADD_GROUP'] . "\" id=\"addGroup\" onclick=\"insertGroup(0)\" />";
            $html .= "</div>";
        }
        $html .= '<input type="hidden" name="vathidden" id="vathidden" value="' . get_select_options_with_id($app_list_strings['vat_list'], '') . '">
				  <input type="hidden" name="discounthidden" id="discounthidden" value="' . get_select_options_with_id($app_list_strings['discount_list'], '') . '">';
        require_once 'modules/AOS_Products_Quotes/AOS_Products_Quotes.php';
        require_once 'modules/AOS_Line_Item_Groups/AOS_Line_Item_Groups.php';
        $sql = "SELECT pg.id, pg.group_id FROM aos_products_quotes pg LEFT JOIN aos_line_item_groups lig ON pg.group_id = lig.id WHERE pg.parent_type = '" . $focus->object_name . "' AND pg.parent_id = '" . $focus->id . "' AND pg.deleted = 0 ORDER BY lig.number ASC, pg.number ASC";
        $result = $focus->db->query($sql);
        $html .= "<script>\n\t\t\tif(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}\n\t\t\t</script>";
        while ($row = $focus->db->fetchByAssoc($result)) {
            $line_item = new AOS_Products_Quotes();
            $line_item->retrieve($row['id']);
            $line_item = json_encode($line_item->toArray());
            $group_item = 'null';
            if ($row['group_id'] != null) {
                $group_item = new AOS_Line_Item_Groups();
                $group_item->retrieve($row['group_id']);
                $group_item = json_encode($group_item->toArray());
            }
            $html .= "<script>\n\t\t\t\t\tinsertLineItems(" . $line_item . "," . $group_item . ");\n\t\t\t\t</script>";
        }
        if (!$enable_groups) {
            $html .= '<script>insertGroup();</script>';
        }
    } else {
        if ($view == 'DetailView') {
            $params = array('currency_id' => $focus->currency_id);
            $sql = "SELECT pg.id, pg.group_id FROM aos_products_quotes pg LEFT JOIN aos_line_item_groups lig ON pg.group_id = lig.id WHERE pg.parent_type = '" . $focus->object_name . "' AND pg.parent_id = '" . $focus->id . "' AND pg.deleted = 0 ORDER BY lig.number ASC, pg.number ASC";
            $result = $focus->db->query($sql);
            $sep = get_number_seperators();
            $html .= "<table border='0' width='100%' cellpadding='0' cellspacing='0'>";
            $i = 0;
            $productCount = 0;
            $serviceCount = 0;
            $group_id = '';
            $groupStart = '';
            $groupEnd = '';
            $product = '';
            $service = '';
            while ($row = $focus->db->fetchByAssoc($result)) {
                $line_item = new AOS_Products_Quotes();
                $line_item->retrieve($row['id']);
                if ($enable_groups && ($group_id != $row['group_id'] || $i == 0)) {
                    $html .= $groupStart . $product . $service . $groupEnd;
                    if ($i != 0) {
                        $html .= "<tr><td colspan='9' nowrap='nowrap'><br></td></tr>";
                    }
                    $groupStart = '';
                    $groupEnd = '';
                    $product = '';
                    $service = '';
                    $i = 1;
                    $productCount = 0;
                    $serviceCount = 0;
                    $group_id = $row['group_id'];
                    $group_item = new AOS_Line_Item_Groups();
                    $group_item->retrieve($row['group_id']);
                    $groupStart .= "<tr>";
                    $groupStart .= "<td class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>&nbsp;</td>";
                    $groupStart .= "<td class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>" . $mod_strings['LBL_GROUP_NAME'] . ":</td>";
                    $groupStart .= "<td class='tabDetailViewDL' colspan='7' style='text-align: left;padding:2px;'>" . $group_item->name . "</td>";
                    $groupStart .= "</tr>";
                    $groupEnd = "<tr><td colspan='9' nowrap='nowrap'><br></td></tr>";
                    $groupEnd .= "<tr>";
                    $groupEnd .= "<td class='tabDetailViewDL' colspan='8' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_TOTAL_AMT'] . ":&nbsp;&nbsp;</td>";
                    $groupEnd .= "<td class='tabDetailViewDL' style='text-align: right;padding:2px;'>" . currency_format_number($group_item->total_amt, $params) . "</td>";
                    $groupEnd .= "</tr>";
                    $groupEnd .= "<tr>";
                    $groupEnd .= "<td class='tabDetailViewDL' colspan='8' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_DISCOUNT_AMOUNT'] . ":&nbsp;&nbsp;</td>";
                    $groupEnd .= "<td class='tabDetailViewDL' style='text-align: right;padding:2px;'>" . currency_format_number($group_item->discount_amount, $params) . "</td>";
                    $groupEnd .= "</tr>";
                    $groupEnd .= "<tr>";
                    $groupEnd .= "<td class='tabDetailViewDL' colspan='8' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_SUBTOTAL_AMOUNT'] . ":&nbsp;&nbsp;</td>";
                    $groupEnd .= "<td class='tabDetailViewDL' style='text-align: right;padding:2px;'>" . currency_format_number($group_item->subtotal_amount, $params) . "</td>";
                    $groupEnd .= "</tr>";
                    $groupEnd .= "<tr>";
                    $groupEnd .= "<td class='tabDetailViewDL' colspan='8' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_TAX_AMOUNT'] . ":&nbsp;&nbsp;</td>";
                    $groupEnd .= "<td class='tabDetailViewDL' style='text-align: right;padding:2px;'>" . currency_format_number($group_item->tax_amount, $params) . "</td>";
                    $groupEnd .= "</tr>";
                    $groupEnd .= "<tr>";
                    $groupEnd .= "<td class='tabDetailViewDL' colspan='8' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_GRAND_TOTAL'] . ":&nbsp;&nbsp;</td>";
                    $groupEnd .= "<td class='tabDetailViewDL' style='text-align: right;padding:2px;'>" . currency_format_number($group_item->total_amount, $params) . "</td>";
                    $groupEnd .= "</tr>";
                }
                if ($line_item->product_id != '0' && $line_item->product_id != null) {
                    if ($productCount == 0) {
                        $product .= "<tr>";
                        $product .= "<td width='5%' class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>&nbsp;</td>";
                        $product .= "<td width='10%' class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>" . $mod_strings['LBL_PRODUCT_QUANITY'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>" . $mod_strings['LBL_PRODUCT_NAME'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_LIST_PRICE'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_DISCOUNT_AMT'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_UNIT_PRICE'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_VAT'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_VAT_AMT'] . "</td>";
                        $product .= "<td width='12%' class='tabDetailViewDL' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_TOTAL_PRICE'] . "</td>";
                        $product .= "</tr>";
                    }
                    $product .= "<tr>";
                    $product_note = wordwrap($line_item->description, 40, "<br />\n");
                    $product .= "<td class='tabDetailViewDF' style='text-align: left; padding:2px;'>" . ++$productCount . "</td>";
                    $product .= "<td class='tabDetailViewDF' style='padding:2px;'>" . rtrim(rtrim(format_number($line_item->product_qty), '0'), $sep[1]) . "</td>";
                    $product .= "<td class='tabDetailViewDF' style='padding:2px;'><a href='index.php?module=AOS_Products&action=DetailView&record=" . $line_item->product_id . "' class='tabDetailViewDFLink'>" . $line_item->name . "</a><br />" . $product_note . "</td>";
                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->product_list_price, $params) . "</td>";
                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . get_discount_string($line_item->discount, $line_item->product_discount, $params, $locale, $sep) . "</td>";
                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->product_unit_price, $params) . "</td>";
                    if ($locale->getPrecision()) {
                        $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . rtrim(rtrim(format_number($line_item->vat), '0'), $sep[1]) . "%</td>";
                    } else {
                        $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . format_number($line_item->vat) . "%</td>";
                    }
                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->vat_amt, $params) . "</td>";
                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->product_total_price, $params) . "</td>";
                    $product .= "</tr>";
                } else {
                    if ($serviceCount == 0) {
                        $service .= "<tr>";
                        $service .= "<td width='5%' class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>&nbsp;</td>";
                        $service .= "<td width='46%' class='dataLabel' style='text-align: left;padding:2px;' colspan='2' scope='row'>" . $mod_strings['LBL_SERVICE_NAME'] . "</td>";
                        $service .= "<td width='12%' class='dataLabel' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_SERVICE_LIST_PRICE'] . "</td>";
                        $service .= "<td width='12%' class='dataLabel' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_SERVICE_DISCOUNT'] . "</td>";
                        $service .= "<td width='12%' class='dataLabel' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_SERVICE_PRICE'] . "</td>";
                        $service .= "<td width='12%' class='dataLabel' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_VAT'] . "</td>";
                        $service .= "<td width='12%' class='dataLabel' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_VAT_AMT'] . "</td>";
                        $service .= "<td width='12%' class='dataLabel' style='text-align: right;padding:2px;' scope='row'>" . $mod_strings['LBL_TOTAL_PRICE'] . "</td>";
                        $service .= "</tr>";
                    }
                    $service .= "<tr>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: left; padding:2px;'>" . ++$serviceCount . "</td>";
                    $service .= "<td class='tabDetailViewDF' style='padding:2px;' colspan='2'>" . $line_item->name . "</td>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->product_list_price, $params) . "</td>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . get_discount_string($line_item->discount, $line_item->product_discount, $params, $locale, $sep) . "</td>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->product_unit_price, $params) . "</td>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . rtrim(rtrim(format_number($line_item->vat), '0'), $sep[1]) . "%</td>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->vat_amt, $params) . "</td>";
                    $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>" . currency_format_number($line_item->product_total_price, $params) . "</td>";
                    $service .= "</tr>";
                }
            }
            $html .= $groupStart . $product . $service . $groupEnd;
            $html .= "</table>";
        }
    }
    return $html;
}
예제 #7
0
    if ($row['discount_amount'] != null) {
        $row['discount_amount'] = format_number($row['discount_amount']);
    }
    if ($row['subtotal_amount'] != null) {
        $row['subtotal_amount'] = format_number($row['subtotal_amount']);
    }
    if ($row['tax_amount'] != null) {
        $row['tax_amount'] = format_number($row['tax_amount']);
    }
    if ($row['subtotal_tax_amount'] != null) {
        $row['subtotal_tax_amount'] = format_number($row['subtotal_tax_amount']);
    }
    if ($row['total_amount'] != null) {
        $row['total_amount'] = format_number($row['total_amount']);
    }
    $group_invoice = new AOS_Line_Item_Groups();
    $group_invoice->populateFromRow($row);
    $group_invoice->save();
}
//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) {