Exemplo n.º 1
0
Arquivo: common.php Projeto: pcela/lms
function r_trim($array)
{
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $array[$key] = r_trim($value);
        } else {
            $array[$key] = trim($value);
        }
    }
    return $array;
}
Exemplo n.º 2
0
        // get default note's numberplanid and next number
        $note['cdate'] = time();
        $note['paytime'] = $CONFIG['notes']['paytime'];
        if (isset($_GET['customerid']) && $_GET['customerid'] != '' && $LMS->CustomerExists($_GET['customerid'])) {
            $customer = $LMS->GetCustomer($_GET['customerid'], true);
            $note['numberplanid'] = $DB->GetOne('SELECT n.id FROM numberplans n
				JOIN numberplanassignments a ON (n.id = a.planid)
				WHERE n.doctype = ? AND n.isdefault = 1 AND a.divisionid = ?', array(DOC_DNOTE, $customer['divisionid']));
        }
        if (empty($note['numberplanid'])) {
            $note['numberplanid'] = $DB->GetOne('SELECT id FROM numberplans
				WHERE doctype = ? AND isdefault = 1', array(DOC_DNOTE));
        }
        break;
    case 'additem':
        $itemdata = r_trim($_POST);
        $itemdata['value'] = f_round($itemdata['value']);
        $itemdata['description'] = $itemdata['description'];
        if ($itemdata['value'] > 0 && $itemdata['description'] != '') {
            $itemdata['posuid'] = (string) getmicrotime();
            $contents[] = $itemdata;
        }
        break;
    case 'deletepos':
        if (sizeof($contents)) {
            foreach ($contents as $idx => $row) {
                if ($row['posuid'] == $_GET['posuid']) {
                    unset($contents[$idx]);
                }
            }
        }
Exemplo n.º 3
0
                $error['number'] = trans('Credit note number $a already exists!', $cnote['number']);
            }
        }
        // finally check if selected customer can use selected numberplan
        $divisionid = !empty($cnote['use_current_division']) ? $invoice['current_divisionid'] : $invoice['divisionid'];
        if ($cnote['numberplanid'] && !$DB->GetOne('SELECT 1 FROM numberplanassignments
			WHERE planid = ? AND divisionid = ?', array($cnote['numberplanid'], $divisionid))) {
            $error['number'] = trans('Selected numbering plan doesn\'t match customer\'s division!');
        }
        break;
    case 'save':
        if (empty($contents) || empty($cnote)) {
            break;
        }
        $SESSION->restore('invoiceid', $invoice['id']);
        $newcontents = r_trim($_POST);
        foreach ($contents as $item) {
            $idx = $item['itemid'];
            $contents[$idx]['taxid'] = isset($newcontents['taxid'][$idx]) ? $newcontents['taxid'][$idx] : $item['taxid'];
            $contents[$idx]['prodid'] = isset($newcontents['prodid'][$idx]) ? $newcontents['prodid'][$idx] : $item['prodid'];
            $contents[$idx]['jm'] = isset($newcontents['jm'][$idx]) ? $newcontents['jm'][$idx] : $item['jm'];
            $contents[$idx]['count'] = isset($newcontents['count'][$idx]) ? $newcontents['count'][$idx] : $item['count'];
            $contents[$idx]['discount'] = str_replace(',', '.', isset($newcontents['discount'][$idx]) ? $newcontents['discount'][$idx] : $item['discount']);
            $contents[$idx]['pdiscount'] = 0;
            $contents[$idx]['vdiscount'] = 0;
            $contents[$idx]['discount_type'] = isset($newcontents['discount_type'][$idx]) ? $newcontents['discount_type'][$idx] : $item['discount_type'];
            if (preg_match('/^[0-9]+(\\.[0-9]+)*$/', $contents[$idx]['discount'])) {
                $contents[$idx]['pdiscount'] = $contents[$idx]['discount_type'] == DISCOUNT_PERCENTAGE ? floatval($contents[$idx]['discount']) : 0;
                $contents[$idx]['vdiscount'] = $contents[$idx]['discount_type'] == DISCOUNT_AMOUNT ? floatval($contents[$idx]['discount']) : 0;
            }
            if ($contents[$idx]['pdiscount'] < 0 || $contents[$idx]['pdiscount'] > 99.90000000000001 || $contents[$idx]['vdiscount'] < 0) {