Fix sql field can't be named 'offset' (reserved word).
This commit is contained in:
parent
8058712d47
commit
d1e7577eed
@ -274,7 +274,15 @@ class DoliDBPgsql extends DoliDB
|
||||
$line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3];
|
||||
}
|
||||
|
||||
// Translate order to drop foreign keys
|
||||
// Translate order to drop primary keys
|
||||
// ALTER TABLE llx_dolibarr_modules DROP PRIMARY KEY pk_xxx
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+PRIMARY\s+KEY\s*([^;]+)$/i',$line,$reg))
|
||||
{
|
||||
$line = "-- ".$line." replaced by --\n";
|
||||
$line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2];
|
||||
}
|
||||
|
||||
// Translate order to drop foreign keys
|
||||
// ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx
|
||||
if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg))
|
||||
{
|
||||
|
||||
@ -64,12 +64,12 @@ else
|
||||
else
|
||||
{
|
||||
$range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat);
|
||||
|
||||
|
||||
if (empty($range)) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
|
||||
else
|
||||
{
|
||||
$offset = price($range->offset, 0, $langs, 1, -1, -1, $conf->currency);
|
||||
echo json_encode(array('up' => $range->coef, 'offset' => $range->offset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline'));
|
||||
$ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency);
|
||||
echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1833,13 +1833,13 @@ class ExpenseReport extends CommonObject
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($conf->global->MAIN_EXPENSE_APPLY_ENTIRE_OFFSET)) $offset = $range->offset;
|
||||
else $offset = $range->offset / 12; // The amount of offset is a global value for the year
|
||||
if (!empty($conf->global->MAIN_EXPENSE_APPLY_ENTIRE_OFFSET)) $ikoffset = $range->ikoffset;
|
||||
else $ikoffset = $range->ikoffset / 12; // The amount of offset is a global value for the year
|
||||
|
||||
// Test if offset has been applied for the current month
|
||||
// Test if ikoffset has been applied for the current month
|
||||
if (!$this->offsetAlreadyGiven())
|
||||
{
|
||||
$new_up = $range->coef + ($offset / $this->line->qty);
|
||||
$new_up = $range->coef + ($ikoffset / $this->line->qty);
|
||||
$tmp = calcul_price_total($this->line->qty, $new_up, 0, $this->line->vatrate, 0, 0, 0, 'TTC', 0, $type, $seller);
|
||||
|
||||
$this->line->value_unit = $tmp[5];
|
||||
@ -1854,7 +1854,7 @@ class ExpenseReport extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* If the sql find any rows then the offset is already given (offset is applied at the first expense report line)
|
||||
* If the sql find any rows then the ikoffset is already given (ikoffset is applied at the first expense report line)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
* \ingroup expenseik
|
||||
* \brief File of class to manage expense ik
|
||||
*/
|
||||
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/coreobject.class.php';
|
||||
|
||||
/**
|
||||
@ -32,30 +32,30 @@ class ExpenseReportIk extends CoreObject
|
||||
public $element='expenseik';
|
||||
public $table_element='expensereport_ik';
|
||||
public $fk_element='fk_expense_ik';
|
||||
|
||||
|
||||
/**
|
||||
* c_exp_tax_cat Id
|
||||
* @var int
|
||||
*/
|
||||
public $fk_c_exp_tax_cat;
|
||||
|
||||
|
||||
/**
|
||||
* c_exp_tax_range id
|
||||
* @var int
|
||||
*/
|
||||
public $fk_range;
|
||||
|
||||
|
||||
/**
|
||||
* Coef
|
||||
* @var double
|
||||
*/
|
||||
public $coef;
|
||||
|
||||
|
||||
/**
|
||||
* Offset
|
||||
* @var double
|
||||
*/
|
||||
public $offset;
|
||||
public $ikoffset;
|
||||
|
||||
/**
|
||||
* Attribute object linked with database
|
||||
@ -66,7 +66,7 @@ class ExpenseReportIk extends CoreObject
|
||||
,'fk_c_exp_tax_cat'=>array('type'=>'integer','index'=>true)
|
||||
,'fk_range'=>array('type'=>'integer','index'=>true)
|
||||
,'coef'=>array('type'=>'double')
|
||||
,'offset'=>array('type'=>'double')
|
||||
,'ikoffset'=>array('type'=>'double')
|
||||
);
|
||||
|
||||
/**
|
||||
@ -74,35 +74,35 @@ class ExpenseReportIk extends CoreObject
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct(DoliDB &$db)
|
||||
public function __construct(DoliDB &$db)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
parent::__construct($db);
|
||||
parent::init();
|
||||
|
||||
|
||||
$this->errors = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return expense categories in array
|
||||
*
|
||||
*
|
||||
* @param int $mode 1=only active; 2=only inactive; other value return all
|
||||
* @return array of category
|
||||
*/
|
||||
public static function getTaxCategories($mode=1)
|
||||
{
|
||||
global $db;
|
||||
|
||||
|
||||
$categories = array();
|
||||
|
||||
|
||||
$sql = 'SELECT rowid, label, entity, active';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat';
|
||||
$sql.= ' WHERE entity IN (0,'. getEntity('').')';
|
||||
if ($mode == 1) $sql.= ' AND active = 1';
|
||||
elseif ($mode == 2) $sql.= 'AND active = 0';
|
||||
|
||||
|
||||
dol_syslog(get_called_class().'::getTaxCategories sql='.$sql, LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
@ -116,23 +116,23 @@ class ExpenseReportIk extends CoreObject
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
|
||||
public static function getRangeByUser(User $userauthor, $fk_c_exp_tax_cat)
|
||||
{
|
||||
$default_range = (int) $userauthor->default_range; // if not defined, then 0
|
||||
$ranges = self::getRangesByCategory($fk_c_exp_tax_cat);
|
||||
|
||||
|
||||
// substract 1 because array start from 0
|
||||
if (empty($ranges) || !isset($ranges[$default_range-1])) return false;
|
||||
else return $ranges[$default_range-1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of ranges for a category
|
||||
*
|
||||
*
|
||||
* @param int $fk_c_exp_tax_cat category id
|
||||
* @param int $active active
|
||||
* @return array
|
||||
@ -140,15 +140,15 @@ class ExpenseReportIk extends CoreObject
|
||||
public static function getRangesByCategory($fk_c_exp_tax_cat, $active=1)
|
||||
{
|
||||
global $db;
|
||||
|
||||
|
||||
$ranges = array();
|
||||
|
||||
|
||||
$sql = 'SELECT r.rowid FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r';
|
||||
if ($active) $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)';
|
||||
$sql.= ' WHERE r.fk_c_exp_tax_cat = '.$fk_c_exp_tax_cat;
|
||||
if ($active) $sql.= ' AND r.active = 1 AND c.active = 1';
|
||||
$sql.= ' ORDER BY r.range_ik';
|
||||
|
||||
|
||||
dol_syslog(get_called_class().'::getRangesByCategory sql='.$sql, LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
@ -160,7 +160,7 @@ class ExpenseReportIk extends CoreObject
|
||||
{
|
||||
$object = new ExpenseReportIk($db);
|
||||
$object->fetch($obj->rowid);
|
||||
|
||||
|
||||
$ranges[] = $object;
|
||||
}
|
||||
}
|
||||
@ -169,28 +169,28 @@ class ExpenseReportIk extends CoreObject
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
return $ranges;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of ranges grouped by category
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllRanges()
|
||||
{
|
||||
global $db;
|
||||
|
||||
|
||||
$ranges = array();
|
||||
|
||||
|
||||
$sql = ' SELECT r.rowid, r.fk_c_exp_tax_cat, r.range_ik, c.label, i.rowid as fk_expense_ik, r.active as range_active, c.active as cat_active';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r';
|
||||
$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'expensereport_ik i ON (r.rowid = i.fk_range)';
|
||||
$sql.= ' WHERE r.entity IN (0, '. getEntity('').')';
|
||||
$sql.= ' ORDER BY r.fk_c_exp_tax_cat, r.range_ik';
|
||||
|
||||
|
||||
dol_syslog(get_called_class().'::getAllRanges sql='.$sql, LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
@ -200,7 +200,7 @@ class ExpenseReportIk extends CoreObject
|
||||
$ik = new ExpenseReportIk($db);
|
||||
if ($obj->fk_expense_ik > 0) $ik->fetch($obj->fk_expense_ik);
|
||||
$obj->ik = $ik;
|
||||
|
||||
|
||||
if (!isset($ranges[$obj->fk_c_exp_tax_cat])) $ranges[$obj->fk_c_exp_tax_cat] = array('label' => $obj->label, 'active' => $obj->cat_active, 'ranges' => array());
|
||||
$ranges[$obj->fk_c_exp_tax_cat]['ranges'][] = $obj;
|
||||
}
|
||||
@ -209,20 +209,20 @@ class ExpenseReportIk extends CoreObject
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
return $ranges;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the max number of range by a category
|
||||
*
|
||||
*
|
||||
* @param int $default_c_exp_tax_cat id
|
||||
* @return int
|
||||
*/
|
||||
public static function getMaxRangeNumber($default_c_exp_tax_cat=0)
|
||||
{
|
||||
global $db,$conf;
|
||||
|
||||
|
||||
$sql = 'SELECT MAX(counted) as nbRange FROM (';
|
||||
$sql.= ' SELECT COUNT(*) as counted';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r';
|
||||
@ -230,7 +230,7 @@ class ExpenseReportIk extends CoreObject
|
||||
if ($default_c_exp_tax_cat > 0) $sql .= ' AND r.fk_c_exp_tax_cat = '.$default_c_exp_tax_cat;
|
||||
$sql.= ' GROUP BY r.fk_c_exp_tax_cat';
|
||||
$sql .= ') as counts';
|
||||
|
||||
|
||||
dol_syslog(get_called_class().'::getMaxRangeNumber sql='.$sql, LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
@ -242,7 +242,7 @@ class ExpenseReportIk extends CoreObject
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +218,8 @@ CREATE TABLE IF NOT EXISTS llx_expensereport_ik (
|
||||
fk_c_exp_tax_cat integer DEFAULT 0 NOT NULL,
|
||||
fk_range integer DEFAULT 0 NOT NULL,
|
||||
coef double DEFAULT 0 NOT NULL,
|
||||
offset double DEFAULT 0 NOT NULL
|
||||
ikoffset double DEFAULT 0 NOT NULL,
|
||||
active integer DEFAULT 1
|
||||
)ENGINE=innodb;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS llx_c_exp_tax_cat (
|
||||
@ -260,21 +261,21 @@ INSERT INTO llx_c_type_fees (code, label, active, accountancy_code) VALUES
|
||||
('EX_PAR_VP', 'ExpLabelParkingPV', 0, '625160'),
|
||||
('EX_CAM_VP', 'ExpLabelMaintenanceRepairPV', 0, '615300');
|
||||
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (1,4, 1, 0.41, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (2,4, 2, 0.244, 824);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (3,4, 3, 0.286, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (4,5, 4, 0.493, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (5,5, 5, 0.277, 1082);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (6,5, 6, 0.332, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (7,6, 7, 0.543, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (8,6, 8, 0.305, 1180);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (9,6, 9, 0.364, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (10,7, 10, 0.568, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (11,7, 11, 0.32, 1244);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (12,7, 12, 0.382, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (13,8, 13, 0.595, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (14,8, 14, 0.337, 1288);
|
||||
INSERT INTO llx_expensereport_ik (rowid,fk_c_exp_tax_cat, fk_range, coef, offset) values (15,8, 15, 0.401, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (1,4, 1, 0.41, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (2,4, 2, 0.244, 824);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (3,4, 3, 0.286, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (4,5, 4, 0.493, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (5,5, 5, 0.277, 1082);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (6,5, 6, 0.332, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (7,6, 7, 0.543, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (8,6, 8, 0.305, 1180);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (9,6, 9, 0.364, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (10,7, 10, 0.568, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (11,7, 11, 0.32, 1244);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (12,7, 12, 0.382, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (13,8, 13, 0.595, 0);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (14,8, 14, 0.337, 1288);
|
||||
INSERT INTO llx_expensereport_ik (rowid, fk_c_exp_tax_cat, fk_range, coef, ikoffset) values (15,8, 15, 0.401, 0);
|
||||
|
||||
|
||||
INSERT INTO llx_c_exp_tax_cat (rowid, label, entity, active) values (1,'ExpAutoCat', 1, 1);
|
||||
@ -415,12 +416,12 @@ DELETE FROM llx_const WHERE name = __ENCRYPT('ACCOUNTING_EXPORT_DEVISE')__;
|
||||
DELETE FROM llx_const WHERE name = __ENCRYPT('ACCOUNTING_EXPORT_PIECE')__;
|
||||
DELETE FROM llx_const WHERE name = __ENCRYPT('ACCOUNTING_EXPENSEREPORT_JOURNAL')__;
|
||||
|
||||
ALTER TABLE llx_c_paiement DROP PRIMARY KEY;
|
||||
-- VMYSQL4.1 ALTER TABLE llx_c_paiement DROP PRIMARY KEY;
|
||||
ALTER TABLE llx_c_paiement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER id;
|
||||
ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement;
|
||||
ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(id, entity, code);
|
||||
|
||||
ALTER TABLE llx_c_payment_term DROP PRIMARY KEY;
|
||||
-- VMYSQL4.1 ALTER TABLE llx_c_payment_term DROP PRIMARY KEY;
|
||||
ALTER TABLE llx_c_payment_term ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
|
||||
ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(rowid, entity, code);
|
||||
|
||||
|
||||
@ -25,5 +25,6 @@ CREATE TABLE IF NOT EXISTS llx_expensereport_ik (
|
||||
fk_c_exp_tax_cat integer DEFAULT 0 NOT NULL,
|
||||
fk_range integer DEFAULT 0 NOT NULL,
|
||||
coef double DEFAULT 0 NOT NULL,
|
||||
offset double DEFAULT 0 NOT NULL
|
||||
ikoffset double DEFAULT 0 NOT NULL,
|
||||
active integer DEFAULT 1
|
||||
)ENGINE=innodb;
|
||||
Loading…
Reference in New Issue
Block a user