TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tbl_item_after_ins_tr AFTER INSERT ON tbl_item FOR EACH ROW
\nBEGIN
\nIF (@DISABLE_TRIGGERS IS NULL) then
\n
\nUPDATE tbl_archive_item SET .tbl_archive_item.it_archive=1 WHERE tbl_archive_item.it_uuid=NEW.it_uuid;
\nCALL proc_update_drug_archive(NEW.it_uuid,1);
\n
\nEND IF;
\nEND' 'CREATE DEFINER=`root`@`localhost` TRIGGER tbl_item_before_del_tr BEFORE DELETE ON tbl_item FOR EACH ROW
\nBEGIN
\nIF (@DISABLE_TRIGGERS IS NULL) then
\nUPDATE tbl_archive_item SET .tbl_archive_item.it_archive=0 WHERE tbl_archive_item.it_uuid=OLD.it_uuid;
\nCALL proc_update_drug_archive(OLD.it_uuid,0);
\nEND IF;
\nEND' 'CREATE DEFINER=`root`@`localhost` TRIGGER tbl_item_before_ins_tr BEFORE INSERT ON tbl_item FOR EACH ROW
\nBEGIN
\nDECLARE v_cl_id integer(11);
\nDECLARE v_cl_code varchar(100);
\nDECLARE v_cl_name varchar(100);
\nDECLARE v_gr_id integer(11);
\nDECLARE v_gr_code varchar(100);
\nDECLARE v_gr_name varchar(100);
\nDECLARE v_it_warranty_period varchar(100);
\nDECLARE v_it_location varchar(100);
\nDECLARE v_it_curr_equal DOUBLE(15,5);
\n
\nIF (@DISABLE_TRIGGERS IS NULL) then
\nIF ISNULL(NEW.it_uuid) THEN
\nSET NEW.it_uuid := UPPER(UUID());
\nEND IF;
\n
\nSELECT cl_id,cl_code,cl_name INTO v_cl_id,v_cl_code,v_cl_name FROM `tbl_item_class`
\nWHERE cl_id=NEW.it_id_class ;
\n
\nSELECT it_gr_id,it_gr_code,it_gr_name INTO v_gr_id,v_gr_code,v_gr_name FROM `tbl_item_group`
\nWHERE it_gr_id=NEW.it_id_group ;
\n
\nSELECT CONCAT(IF(NEW.it_warranty_val=0,\'\',NEW.it_warranty_val),\' \',view_st_warranty.st_desc) INTO v_it_warranty_period FROM
\n`view_st_warranty`   WHERE view_st_warranty.`st_id`=NEW.it_warranty_type;
\n
\nSELECT tbl_statements .st_desc INTO v_it_location
\nFROM
\ntbl_statements  WHERE tbl_statements.st_id=NEW.it_id_location;
\n
\nSET NEW.`it_warrinty_period` = v_it_warranty_period;
\nSET NEW.`it_location` = v_it_location;
\nSET NEW.`it_cl_code` = v_cl_code;
\nSET NEW.`it_cl_name` = v_cl_name;
\nSET NEW.`it_gr_code` = v_gr_code;
\nSET NEW.`it_gr_name` = v_gr_name;
\n
\nIF NEW.`it_un_price_cost_avg` = 0 THEN
\nSET v_it_curr_equal=1;
\nIF NEW.it_currency_id<>1 THEN
\nSELECT cu_equal INTO v_it_curr_equal FROM `tbl_currency`
\nWHERE (NEW.it_currency_id=cu_id);
\nEND IF;
\nSET NEW.it_un_price_cost_avg =IF(NEW.it_un_price_buy=0,NEW.it_un_price_cost,NEW.it_un_price_buy)*v_it_curr_equal;
\nEND IF;
\n
\nEND IF;
\nEND' 'CREATE DEFINER=`root`@`localhost` TRIGGER tbl_item_before_upd_tr BEFORE UPDATE ON tbl_item FOR EACH ROW
\nBEGIN
\nDECLARE v_cl_id integer(11);
\nDECLARE v_cl_code varchar(100);
\nDECLARE v_cl_name varchar(100);
\nDECLARE v_gr_id integer(11);
\nDECLARE v_gr_code varchar(100);
\nDECLARE v_gr_name varchar(100);
\nDECLARE v_it_warranty_period varchar(100);
\nDECLARE v_it_location varchar(100);
\nDECLARE v_cc_id integer(11);
\nDECLARE v_cc_code varchar(100);
\nDECLARE v_cc_name varchar(100);
\nDECLARE v_it_curr_equal DOUBLE(15,5);
\n
\nIF (@DISABLE_TRIGGERS IS NULL) then
\nIF (NEW.it_id_class<>OLD.it_id_class) OR
\n(NEW.it_id_group<>OLD.it_id_group) OR
\n(NEW.it_warranty_type<>OLD.it_warranty_type) OR
\n(NEW.it_warranty_val<>OLD.it_warranty_val) OR
\n(NEW.it_id_location<>OLD.it_id_location)
\nTHEN
\n
\nSELECT cl_id,cl_code,cl_name INTO v_cl_id,v_cl_code,v_cl_name FROM `tbl_item_class`
\nWHERE cl_id=NEW.it_id_class ;
\n
\nSELECT it_gr_id,it_gr_code,it_gr_name INTO v_gr_id,v_gr_code,v_gr_name FROM `tbl_item_group`
\nWHERE it_gr_id=NEW.it_id_group ;
\n
\nSELECT CONCAT(IF(NEW.it_warranty_val=0,\'\',NEW.it_warranty_val),\' \',view_st_warranty.st_desc) INTO v_it_warranty_period FROM
\n`view_st_warranty`   WHERE view_st_warranty.`st_id`=NEW.it_warranty_type;
\n
\nSELECT tbl_statements .st_desc INTO v_it_location
\nFROM
\ntbl_statements  WHERE tbl_statements.st_id=NEW.it_id_location;
\n
\nSET NEW.`it_warrinty_period` = v_it_warranty_period;
\nSET NEW.`it_location` = v_it_location;
\nSET NEW.`it_cl_code` = v_cl_code;
\nSET NEW.`it_cl_name` = v_cl_name;
\nSET NEW.`it_gr_code` = v_gr_code;
\nSET NEW.`it_gr_name` = v_gr_name;
\nEND IF;
\n
\nIF NEW.`it_un_price_cost_avg` = 0 THEN
\nSET v_it_curr_equal=1;
\nIF NEW.it_currency_id<>1 THEN
\nSELECT cu_equal INTO v_it_curr_equal FROM `tbl_currency`
\nWHERE (NEW.it_currency_id=cu_id);
\nEND IF;
\nSET NEW.it_un_price_cost_avg =IF(NEW.it_un_price_buy=0,NEW.it_un_price_cost,NEW.it_un_price_buy)*v_it_curr_equal;
\nEND IF;
\n
\nEND IF;
\nEND'
sql_modes=1344274434 1344274434 1344274434 1344274434
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
client_cs_names='cp1256' 'cp1256' 'cp1256' 'cp1256'
connection_cl_names='cp1256_general_ci' 'cp1256_general_ci' 'cp1256_general_ci' 'cp1256_general_ci'
db_cl_names='cp1256_general_ci' 'cp1256_general_ci' 'cp1256_general_ci' 'cp1256_general_ci'
