--
--
-- To add a column:         ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;
-- To rename a column:      ALTER TABLE llx_table RENAME COLUMN COLUMN oldname newname varchar(60);
-- To rename column type of field: ALTER TABLE llx_table MODIFY name varchar(60);
--

ALTER TABLE llx_return ADD COLUMN fk_projet integer DEFAULT NULL AFTER fk_soc;
ALTER TABLE llx_return ADD COLUMN label varchar(255) AFTER ref;
ALTER TABLE llx_return ADD COLUMN model_pdf	varchar(255) AFTER note_public;
ALTER TABLE llx_return ADD COLUMN extraparams varchar(255) AFTER model_pdf;
ALTER TABLE llx_return ADD COLUMN fk_user_modif integer DEFAULT NULL AFTER date_return;

ALTER TABLE llx_returndet ADD COLUMN fk_product integer AFTER fk_entrepot;
ALTER TABLE llx_returndet ADD COLUMN qty_asked integer AFTER fk_product;
ALTER TABLE llx_returndet ADD COLUMN qty_sent integer AFTER qty_asked;
ALTER TABLE llx_returndet ADD COLUMN label varchar(255) AFTER qty_sent;
ALTER TABLE llx_returndet ADD COLUMN line_comment text AFTER rang;
ALTER TABLE llx_returndet ADD COLUMN partial_line boolean AFTER line_comment;

UPDATE llx_commande_extrafields AS ce LEFT JOIN llx_commande AS c ON c.rowid = ce.fk_object SET ce.return_status = 1 WHERE c.fk_statut = 5;
UPDATE llx_commande_extrafields AS ce LEFT JOIN llx_commande AS c ON c.rowid = ce.fk_object SET ce.return_status = 2 WHERE c.fk_statut = 6;
UPDATE llx_commande SET fk_statut = 3 WHERE fk_statut > 3;

-- update to new productreturn tables and fields (from return module)

ALTER TABLE llx_productreturn DROP FOREIGN KEY fk_return_fk_soc;
ALTER TABLE llx_productreturn DROP FOREIGN KEY fk_return_fk_user_author;
ALTER TABLE llx_productreturn DROP FOREIGN KEY fk_return_fk_user_valid;
ALTER TABLE llx_productreturn DROP INDEX idx_return_uk_ref;
ALTER TABLE llx_productreturn DROP INDEX idx_return_fk_soc;
ALTER TABLE llx_productreturn DROP INDEX idx_return_fk_user_author;
ALTER TABLE llx_productreturn DROP INDEX idx_return_fk_user_valid;

ALTER TABLE llx_productreturndet CHANGE fk_return fk_productreturn INT(11) NOT NULL;
ALTER TABLE llx_productreturndet DROP FOREIGN KEY fk_returndet_fk_return;
ALTER TABLE llx_productreturndet DROP INDEX idx_returndet_fk_return;
ALTER TABLE llx_productreturndet DROP INDEX idx_origin;

ALTER TABLE llx_productreturndet_batch CHANGE fk_returndet fk_productreturndet INT(11) NOT NULL;
ALTER TABLE llx_productreturndet_batch DROP FOREIGN KEY fk_returndet_batch_fk_returndet;
ALTER TABLE llx_productreturndet_batch DROP INDEX idx_fk_returndet;
UPDATE llx_commande_extrafields SET productreturn_status = return_status WHERE return_status IS NOT NULL AND return_status > 0;
ALTER TABLE llx_commande_extrafields DROP COLUMN return_status;
ALTER TABLE llx_productreturn MODIFY ref_customer varchar(255);

ALTER TABLE llx_productreturndet ADD COLUMN fk_product integer AFTER fk_entrepot;
ALTER TABLE llx_productreturndet ADD COLUMN qty_asked integer AFTER fk_product;
ALTER TABLE llx_productreturndet ADD COLUMN qty_sent integer AFTER qty_asked;
ALTER TABLE llx_productreturndet ADD COLUMN label varchar(255) AFTER qty_sent;
ALTER TABLE llx_productreturndet ADD COLUMN line_comment text AFTER rang;
ALTER TABLE llx_productreturndet ADD COLUMN partial_line boolean AFTER line_comment;
