====== pears.NetClientAddShiftsOneDay ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetClientAddShiftsOneDay"( in "pWebUserID" char(20),in "pvacancyid" char(20),in "pshifttemplateid" char(20),in "pdate" date,
in "ptimefrom" char(25) default null,in "ptimeto" char(25) default null,in "pBreak" char(20) default null,in "pTheirRef" char(50) default null,in "pNote" char(50) default null,in "pQty" char(20) default null,
in "pOrderReason" char(50) default null,in "pSkills" char(100) default null,in "pGrade" char(50) default null,in "pWebUserName" char(50) default null,in "pCanAuthorise" smallint default 0,inout "pLog" long varchar )
-- 20130123 check whether order reason is compulsory before inserting
begin
declare "sid" char(20);
declare "cnt" integer;
declare "i" integer;
declare "tfrom" time;
declare "tto" time;
declare "ibreak" integer;
declare "slog" char(200);
declare "isReasonCompulsory" integer;
if "pdate" is null then
return
end if;
set "i" = "charindex"('|',"pshifttemplateid");
if "i" > 0 then -- Get rid of any extra info tacked onto the code
set "pshifttemplateid" = "left"("pshifttemplateid","i"-1)
end if;
if "trim"("isnull"("pshifttemplateid",'')) = '' then
return
end if;
set "cnt" = "isnull"("iqxnetstringtointeger"("pqty"),0);
if "cnt" <= 0 then
return
end if;
set "tfrom" = "iqxnetstringtotime"("ptimefrom");
set "tto" = "iqxnetstringtotime"("ptimeto");
set "ibreak" = "iqxnetstringtointeger"("pbreak"); -- If times and break not supplied they will come from the template
set "slog" = (select "string"("dateformat"("pdate",'dd/mm/yyyy'),' ',"dateformat"("isnull"("tfrom","timefrom"),'hh:nn'),'-',"dateformat"("isnull"("tto","timeto"),'hh:nn'),' ',"description",' Qty: ',"cnt")
from "tempshifttemplate" where "tempshifttemplateid" = "pshifttemplateid");
if "trim"("isnull"("pnote",'')) <> '' then
set "slog" = "string"("slog",' Note: ',"pnote")
end if;
while "cnt" > 0 loop
set "sid" = "uniquekey"("cnt");
set "isReasonCompulsory" = (select first "ShiftOrderReasonRequired" from "TempShiftTemplate" where "TempShiftTemplateID" = "pshifttemplateid");
if "pOrderReason" = '' and "isReasonCompulsory" = 1 then
select '105~Reason is compulsory';
return
end if;
insert into "tempshiftplan"( "TempShiftPlanID","VacancyID","TimeFrom","TimeTo","BreakMinutes","ShiftDate","Moveable","Description","ClientNote","EssentialSkill","EssentialSkillChoiceList","EssentialSkillGradeID","ReferenceCode","ReferenceRequired","ClientMustConfirm","TempMustConfirm","OrderedBy","TempShiftTypeID","AnalysisCode","RecoveryHours","TempShiftOrderReasonID" )
select "sid","pvacancyid","isnull"("tfrom","timefrom"),"isnull"("tto","timeto"),"isnull"("ibreak","breakminutes"),"pdate","Moveable","Description","pNote","string"("taglocation",';',"tagid",';',"tagchoiceid",';',"gradetagid"),"replace"("pskills","char"(9),';'),"pgrade","ucase"("pTheirRef"),"ReferenceRequired","ClientMustConfirm","TempMustConfirm","pWebUserName","TempShiftTypeID","AnalysisCode","RecoveryHours","nullif"("pOrderReason",'')
from "tempshifttemplate" where "tempshifttemplateid" = "pshifttemplateid";
call "NetSetShiftPlanCascade"("sid");
if "pCanAuthorise" = 0 then
insert into "tempshift"( "tempshiftid","vacancyid","shiftdate","timefrom","timeto","breakminutes","state","tempshiftplanid","cancelreason" )
select "sid","pvacancyid","pdate","isnull"("tfrom","timefrom"),"isnull"("tto","timeto"),"isnull"("ibreak","breakminutes"),'C',"sid",'~'
from "tempshifttemplate" where "tempshifttemplateid" = "pshifttemplateid"
end if;
set "cnt" = "cnt"-1
end loop;
set "pLog" = "string"("pLog","slog","char"(13),"char"(10))
end
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetClientAddShiftsOneDay" IS
{create procedure pears."NetClientAddShiftsOneDay"( in "pWebUserID" char(20),in "pvacancyid" char(20),in "pshifttemplateid" char(20),in "pdate" date,
in "ptimefrom" char(25) default null,in "ptimeto" char(25) default null,in "pBreak" char(20) default null,in "pTheirRef" char(50) default null,in "pNote" char(50) default null,in "pQty" char(20) default null,
in "pOrderReason" char(50) default null,in "pSkills" char(100) default null,in "pGrade" char(50) default null,in "pWebUserName" char(50) default null,in "pCanAuthorise" smallint default 0,inout "pLog" long varchar )
-- 20130123 check whether order reason is compulsory before inserting
begin
declare "sid" char(20);
declare "cnt" integer;
declare "i" integer;
declare "tfrom" time;
declare "tto" time;
declare "ibreak" integer;
declare "slog" char(200);
declare "isReasonCompulsory" integer;
if "pdate" is null then
return
end if;
set "i" = "charindex"('|',"pshifttemplateid");
if "i" > 0 then -- Get rid of any extra info tacked onto the code
set "pshifttemplateid" = "left"("pshifttemplateid","i"-1)
end if;
if "trim"("isnull"("pshifttemplateid",'')) = '' then
return
end if;
set "cnt" = "isnull"("iqxnetstringtointeger"("pqty"),0);
if "cnt" <= 0 then
return
end if;
set "tfrom" = "iqxnetstringtotime"("ptimefrom");
set "tto" = "iqxnetstringtotime"("ptimeto");
set "ibreak" = "iqxnetstringtointeger"("pbreak"); -- If times and break not supplied they will come from the template
set "slog" = (select "string"("dateformat"("pdate",'dd/mm/yyyy'),' ',"dateformat"("isnull"("tfrom","timefrom"),'hh:nn'),'-',"dateformat"("isnull"("tto","timeto"),'hh:nn'),' ',"description",' Qty: ',"cnt")
from "tempshifttemplate" where "tempshifttemplateid" = "pshifttemplateid");
if "trim"("isnull"("pnote",'')) <> '' then
set "slog" = "string"("slog",' Note: ',"pnote")
end if;
while "cnt" > 0 loop
set "sid" = "uniquekey"("cnt");
set "isReasonCompulsory" = (select first "ShiftOrderReasonRequired" from "TempShiftTemplate" where "TempShiftTemplateID" = "pshifttemplateid");
if "pOrderReason" = '' and "isReasonCompulsory" = 1 then
select '105~Reason is compulsory';
return
end if;
insert into "tempshiftplan"( "TempShiftPlanID","VacancyID","TimeFrom","TimeTo","BreakMinutes","ShiftDate","Moveable","Description","ClientNote","EssentialSkill","EssentialSkillChoiceList","EssentialSkillGradeID","ReferenceCode","ReferenceRequired","ClientMustConfirm","TempMustConfirm","OrderedBy","TempShiftTypeID","AnalysisCode","RecoveryHours","TempShiftOrderReasonID" )
select "sid","pvacancyid","isnull"("tfrom","timefrom"),"isnull"("tto","timeto"),"isnull"("ibreak","breakminutes"),"pdate","Moveable","Description","pNote","string"("taglocation",';',"tagid",';',"tagchoiceid",';',"gradetagid"),"replace"("pskills","char"(9),';'),"pgrade","ucase"("pTheirRef"),"ReferenceRequired","ClientMustConfirm","TempMustConfirm","pWebUserName","TempShiftTypeID","AnalysisCode","RecoveryHours","nullif"("pOrderReason",'')
from "tempshifttemplate" where "tempshifttemplateid" = "pshifttemplateid";
call "NetSetShiftPlanCascade"("sid");
if "pCanAuthorise" = 0 then
insert into "tempshift"( "tempshiftid","vacancyid","shiftdate","timefrom","timeto","breakminutes","state","tempshiftplanid","cancelreason" )
select "sid","pvacancyid","pdate","isnull"("tfrom","timefrom"),"isnull"("tto","timeto"),"isnull"("ibreak","breakminutes"),'C',"sid",'~'
from "tempshifttemplate" where "tempshifttemplateid" = "pshifttemplateid"
end if;
set "cnt" = "cnt"-1
end loop;
set "pLog" = "string"("pLog","slog","char"(13),"char"(10))
end
}