Fixed exchange rate storage in GRN transactions.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 4 Jan 2015 18:18:40 +0000 (19:18 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 5 Jan 2015 08:45:17 +0000 (09:45 +0100)
purchasing/includes/db/grn_db.inc
sql/en_US-demo.sql
sql/en_US-new.sql

index d927fd64b66978af13a98e3324202d5a765be259..09090c302fc6a2bf08b3afbab50f94bfd2b0653b 100644 (file)
@@ -99,7 +99,14 @@ function add_grn(&$po)
        begin_transaction();
        hook_db_prewrite($po, ST_SUPPRECEIVE);
 
-       add_new_exchange_rate(get_supplier_currency($po->supplier_id), $date_, $po->ex_rate);
+       if (!is_company_currency($po->curr_code))
+       {
+               if (!$po->ex_rate)
+                       $po->ex_rate = get_date_exchange_rate($po->curr_code, $date_);
+               else
+                       add_new_exchange_rate($po->curr_code, $date_, $po->ex_rate);
+       } else
+               $po->ex_rate = 1;
 
        $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_, $po->ex_rate);
 
index cfb9f2f195cd97597734bfdff2d5c69490aa9bc2..3943dfde1f5d0e94937e32dca55d2435b8e98d6b 100644 (file)
@@ -952,6 +952,7 @@ CREATE TABLE IF NOT EXISTS `0_grn_batch` (
   `reference` varchar(60) NOT NULL default '',
   `delivery_date` date NOT NULL default '0000-00-00',
   `loc_code` varchar(5) default NULL,
+  `rate` double NULL default '1'
   PRIMARY KEY  (`id`),
   KEY `delivery_date` (`delivery_date`),
   KEY `purch_order_no` (`purch_order_no`)
@@ -961,7 +962,7 @@ CREATE TABLE IF NOT EXISTS `0_grn_batch` (
 -- Dumping data for table `0_grn_batch`
 --
 
-INSERT INTO `0_grn_batch` VALUES(1, 2, 1, '1', '2014-06-21', 'DEF');
+INSERT INTO `0_grn_batch` VALUES(1, 2, 1, '1', '2014-06-21', 'DEF', '1');
 
 -- --------------------------------------------------------
 
index 0047971b583b241d68acbf3c04e90f2143385192..1c20185b5b88a9ecd7f7bbc011718298df999b55 100644 (file)
@@ -807,6 +807,7 @@ CREATE TABLE IF NOT EXISTS `0_grn_batch` (
   `reference` varchar(60) NOT NULL default '',
   `delivery_date` date NOT NULL default '0000-00-00',
   `loc_code` varchar(5) default NULL,
+  `rate` double NULL default '1',
   PRIMARY KEY  (`id`),
   KEY `delivery_date` (`delivery_date`),
   KEY `purch_order_no` (`purch_order_no`)