################################################################################################################
########### Create Temp Tables For Web   #######################################################################
################################################################################################################

##################### Production Tables #####################

create table temp_production like production;
create table temp_productiondt like productiondt;

ALTER TABLE temp_production ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_production ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_productiondt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_productiondt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


##################### Delivery Tables #####################

create table temp_deliveries like deliveries;
create table temp_deliverydt like deliverydt;

ALTER TABLE temp_deliveries ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_deliveries ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_deliverydt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_deliverydt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


##################### Purchase Tables #####################

create table temp_purchases like purchases;
create table temp_purchasesdt like purchasesdt;
create table temp_purchasesserialno like purchasesserialno;
create table temp_purchasecharges like purchasecharges;

ALTER TABLE temp_purchases ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_purchases ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_purchasesdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_purchasesdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_purchasesserialno ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_purchasesserialno ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_purchasecharges ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_purchasecharges ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE purchasesserialno ADD INDEX `Idx_JournalType`(`Journal_Type`);
ALTER TABLE temp_purchasesserialno ADD INDEX `Idx_JournalType`(`Journal_Type`);


##################### GRN Tables #####################

create table grnpurchases like purchases;
create table grnpurchasesdt like purchasesdt;

create table temp_grnpurchases like temp_purchases;
create table temp_grnpurchasesdt like temp_purchasesdt;


##################### Purchase Order Tables #####################

create table temp_porder like porder;
create table temp_porderdt like porderdt;

ALTER TABLE temp_porder ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_porder ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_porderdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_porderdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);



##################### Retail Tables #####################

create table temp_retail like retail;
create table temp_retaildt like retaildt;

ALTER TABLE temp_retail ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_retail ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_retaildt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_retaildt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


##################### Sales Tables #####################

create table temp_sales like sales;
create table temp_salesdt like salesdt;

ALTER TABLE temp_sales ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_sales ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_salesdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_salesdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


##################### SalesOrder Tables #####################

create table temp_sorder like sorder;
create table temp_sorderdt like sorderdt;

ALTER TABLE temp_sorder ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_sorder ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_sorderdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_sorderdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);



##################### Trans Tables #####################

create table temp_trans like trans;
create table temp_transdt like transdt;
create table `accesslabels`.temp_acclink like `accesslabels`.`acclink`;
create table temp_cstjourdt like cstjourdt;
create table temp_chkjourdt like chkjourdt;
create table temp_billjourdt like billjourdt;

ALTER TABLE temp_trans ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_trans ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_transdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_transdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE `accesslabels`.temp_acclink ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE `accesslabels`.temp_acclink ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_cstjourdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_cstjourdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_chkjourdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_chkjourdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_billjourdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_billjourdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


##################### Transfer Tables #####################

create table temp_transfer like transfer;
create table temp_transferdt like transferdt;

ALTER TABLE temp_transfer ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_transfer ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_transferdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_transferdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


##################### Journal Tables #####################

create table temp_journal like journal;
create table temp_journaldt like journaldt;

ALTER TABLE temp_journal ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_journal ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_journaldt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_journaldt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


create table temp_cstjour like cstjour;

ALTER TABLE `temp_cstjour` ADD CONSTRAINT `journaldt_id` FOREIGN KEY `journaldt_id` (`Journaldt_id`)
    REFERENCES `temp_journaldt` (`Journaldt_id`)
    ON DELETE CASCADE
    ON UPDATE RESTRICT;

create table temp_chkjour like chkjour;

ALTER TABLE `temp_chkjour` ADD CONSTRAINT `FK_temp_chkjour_1` FOREIGN KEY `FK_temp_chkjour_1` (`Journaldt_id`)
    REFERENCES `temp_journaldt` (`Journaldt_id`)
    ON DELETE CASCADE
    ON UPDATE RESTRICT;


create table temp_billjour like billjour;

ALTER TABLE `temp_billjour` ADD CONSTRAINT `FK_temp_billjour_1` FOREIGN KEY `FK_temp_billjour_1` (`Journaldt_id`)
    REFERENCES `temp_journaldt` (`Journaldt_id`)
    ON DELETE CASCADE
    ON UPDATE RESTRICT;

#########################################################################################################

##################### Adjustment Tables #####################

create table temp_adjustment like adjustment;
create table temp_adjustmentdt like adjustmentdt;

ALTER TABLE temp_adjustment ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_adjustment ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_adjustmentdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_adjustmentdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

#########################################################################################################

##################### SalesJV Tables #####################

create table temp_salesjv like salesjv;
create table temp_salesjvdt like salesjvdt;

ALTER TABLE temp_salesjv ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_salesjv ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_salesjvdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_salesjvdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


#########################################################################################################

##################### PurchasesJV Tables #####################

create table temp_purchasesjv like purchasesjv;
create table temp_purchasesjvdt like purchasesjvdt;

ALTER TABLE temp_purchasesjv ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_purchasesjv ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_purchasesjvdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_purchasesjvdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);



#########################################################################################################

##################### Production Tables #####################

create table temp_productionHD like productionHD;
create table temp_productionHDDivisions like productionHDDivisions;
create table temp_productionRM like productionRM;
create table temp_productionFG like productionFG;

ALTER TABLE temp_productionHD ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_productionHD ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_productionRM ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_productionRM ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_productionFG ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_productionFG ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


#########################################################################################################

##################### Charges Tables #####################

create table temp_ChargesHD like ChargesHD;
create table temp_ChargesDT like ChargesDT;
create table temp_ChargesPurchases like ChargesPurchases;
create table temp_ChargesItems like ChargesItems;
create table temp_ChargesItemsDt like ChargesItemsDt;

ALTER TABLE temp_ChargesHD ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_ChargesHD ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_ChargesPurchases ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_ChargesPurchases ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_ChargesItems ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_ChargesItems ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


#########################################################################################################

##################### ProductionRequest Tables #####################

create table Temp_ProductionRequest like ProductionRequest;
create table Temp_ProductionReqDivisions like ProductionReqDivisions;
create table Temp_ProductionReqRM like ProductionReqRM;
create table Temp_ProductionReqFG like ProductionReqFG;

ALTER TABLE Temp_ProductionRequest ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE Temp_ProductionRequest ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE Temp_ProductionReqRM ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE Temp_ProductionReqRM ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE Temp_ProductionReqFG ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE Temp_ProductionReqFG ADD INDEX `Idx_LoggedCode`(`Logged_Code`);



#########################################################################################################

##################### PrePayment Tables #####################


create table Temp_PrepaymentM like PrepaymentM;
create table Temp_PrepaymentD like PrepaymentD;

ALTER TABLE Temp_PrepaymentM ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE Temp_PrepaymentM ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE Temp_PrepaymentD ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE Temp_PrepaymentD ADD INDEX `Idx_LoggedCode`(`Logged_Code`);


#########################################################################################################

##################### Payment Request Tables #####################

create table temp_paymentrqst like paymentrqst;
create table temp_paymentrqstdt like paymentrqstdt;
create table temp_cstrqst like cstrqst;
create table temp_chkrqst like chkrqst;
create table temp_billrqst like billrqst;

ALTER TABLE temp_paymentrqst ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_paymentrqst ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_paymentrqstdt ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_paymentrqstdt ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_cstrqst ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_cstrqst ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_chkrqst ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_chkrqst ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

ALTER TABLE temp_billrqst ADD COLUMN `Logged_Code` VARCHAR(10) ;
ALTER TABLE temp_billrqst ADD INDEX `Idx_LoggedCode`(`Logged_Code`);

