Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Unnamed
Thursday, August 16th, 2007 at 11:15:01pm MDT 

  1. function ProcessTimeSlip($slipid){
  2. //return and aray called $tresults
  3. // Transfer Process is Broken up into 2 sections , if successful on transfering the data to Tigerpaw, it will transfer the information to payroll to be processed.
  4. $query = "SELECT *,
  5. cast(datediff(mi, StartTime, EndTime)/60 as int) as Hours,
  6. datediff(mi, StartTime, EndTime) - (cast(datediff(mi, StartTime, EndTime)/60 as int) * 60) as Minutes
  7. FROM dbo.TimeSlipDetail
  8. INNER JOIN dbo.Employees
  9. ON dbo.Employees.Employenum = dbo.TimeSlipDetail.EmployeNum
  10. WHERE SlipID = '$slipid'
  11. AND Transfered = 'FALSE'";
  12. $qres = mssql_query($query) or die("<status>Unable To Retrieve Associated Details: ".mssql_get_last_message()."</status></dataset></pagedata>");
  13. $count = mssql_num_rows($qres);
  14. if($count==0){
  15.         $tresult['TPCode'] = NULL;
  16.         $tresult['TPMsg'] = "Time Slip Not Found";
  17.         $tresult['TPError'] = TRUE;
  18.         return $tresults;
  19.         }
  20. for($i=0;$i<$count;$i++){
  21.         mssql_select_db("TimeLogsSQL");
  22.         $detail = mssql_fetch_assoc($qres);
  23.         mssql_select_db("BBCTest");
  24.         $true = 1;
  25.         $false = 0;
  26.         $null = null;
  27.         print_r($detail);
  28.         $inttime1 = strtotime($detail['StartTime']);
  29.         $inttime2 = strtotime($detail['EndTime']);
  30.         $Date1 = date("Y-m-d h:i:000",$inttime1);
  31.         $Date2 = date("Y-m-d h:i:000",$inttime1);
  32.         echo "$Date1";
  33.         /* prepare the statement resource */
  34.         $stmt = mssql_init("tsp_CreateSOLog") or die("<status>Unable To Intialize RSP: ".mssql_get_last_message()."</status></dataset></pagedata>");
  35.         /* now bind the parameters to it */
  36.         mssql_bind($stmt, "@StartDateTime",    $Date1,    SQLINT4,    FALSE);
  37.         mssql_bind($stmt, "@EndDateTime",  $Date2,  SQLVARCHAR, FALSE);
  38.         mssql_bind($stmt, "@LogReason", $detail['Job'], SQLVARCHAR, FALSE);   
  39.         mssql_bind($stmt, "@RepNumber", $detail['TPRep'], SQLINT4, FALSE);
  40.         mssql_bind($stmt, "@ActualHours", $detail['Hours'], SQLINT2, FALSE);
  41.         mssql_bind($stmt, "@ActualMinutes", $detail['Minutes'], SQLINT2, FALSE);
  42.         mssql_bind($stmt, "@Mileage", $detail['Mileage'], SQLFLT8, FALSE);
  43.         mssql_bind($stmt, "@SONumber", $detail['SONumber'], SQLINT4, FALSE);
  44.         mssql_bind($stmt, "@Billable", $true, SQLBIT, FALSE);
  45.         mssql_bind($stmt, "@Chargable", $false, SQLBIT, FALSE);
  46.         mssql_bind($stmt, "@LogComment", $null, SQLVARCHAR, FALSE);
  47.         mssql_bind($stmt, "@Tolls", $null, SQLFLT8, FALSE);
  48.         mssql_bind($stmt, "@Meals", $null, SQLFLT8, FALSE);
  49.         mssql_bind($stmt, "@MiscExpenses", $null, SQLFLT8, FALSE);
  50.         mssql_bind($stmt, "@Fuel", $null, SQLFLT8, FALSE);
  51.         mssql_bind($stmt, "@Parking", $null, SQLFLT8, FALSE);
  52.         mssql_bind($stmt, "@Accomodations", $null, SQLFLT8, FALSE);
  53.         mssql_bind($stmt, "@LaborRate", $null, SQLFLT8, FALSE);
  54.         mssql_bind($stmt, "@SOLogKeyID", $SOLogKeyID, SQLINT4, FALSE);
  55.         mssql_bind($stmt, "@ReturnCode", $ReturnCode, SQLINT4, FALSE);
  56.        
  57.         /* now execute the procedure */
  58.         $result = mssql_execute($stmt) or die("<status>Unable To Execute RSP: ".mssql_get_last_message()."</status><error>TRUE</error></dataset></pagedata>");
  59.         $req = mssql_fetch_row($result);
  60.         if($ReturnCode!=0){
  61.         $tresult['TPCode'][$i] = $ReturnCode;
  62.         $tresult['TPMsg'][$i] = "Time Slip Not Found";
  63.         $tresult['TPError'][$i] = TRUE;
  64.         }
  65.         elseif($ReturnCode==0){
  66.         $tresult['TPCode'][$i] = $ReturnCode;
  67.         $tresult['TPMsg'][$i] = "Time Slip Not Found";
  68.         $tresult['TPError'][$i] = TRUE; 
  69.         }
  70.         else{
  71.         $tresult['TPMsg'][$i] = $ReturnCode;
  72.         }
  73.         echo $ReturnCode;
  74.         echo $SOLogKeyID;
  75.         unset($stmt);
  76.         }
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83. /////////////////////////
  84.  
  85. Here is the Stored Procedure
  86.  
  87.  
  88. /////////////////////////
  89.  
  90. /*********************************************************/
  91. /* File written by SQL Server SysComments Decryptor v1.1 */
  92. /* Copyright (C) 2001 dOMNAR                             */
  93. /*********************************************************/
  94.  
  95. USE BBC
  96. go
  97.  
  98. -----------------------------------------------------------
  99. -- Type: Stored Procedure
  100. -- Name: tsp_CreateSoLog
  101. -----------------------------------------------------------
  102.  
  103.  
  104.  
  105.  
  106. CREATE PROCEDURE dbo.tsp_CreateSoLog      (@SONumber       int,
  107.                                                 @StartDateTime    datetime,
  108.                                                 @EndDateTime       datetime,
  109.                                                 @LogComment         varchar(3000),
  110.                                                 @LogReason           varchar(50),
  111.                                                 @RepNumber            int,
  112.                                                 @ActualHours        int,
  113.                                                 @ActualMinutes    smallint,
  114.                                                 @Billable              bit,
  115.                                                 @Chargable            bit,
  116.                                                 @Mileage                real,
  117.                                                 @Tolls      money,   
  118.                                                 @Meals      money,
  119.                                                 @MiscExpenses      money,
  120.                                                 @Fuel         money,
  121.                                                 @Parking                money,
  122.                                                 @Accomodations  money,
  123.                                                 @LaborRate            money,
  124.                                                 @SOLogKeyID       int OUTPUT,
  125.                                                 @ReturnCode          int OUTPUT)
  126. WITH ENCRYPTION AS
  127.  
  128. DECLARE @ContractNumber  int,
  129.                 @AccountNumber  int,
  130.                 @TotalUnits          decimal (10,2),
  131.                 @UnitFactor          float,
  132.                 @Reason  varchar(50),
  133.                 @Basis      varchar(1),
  134.                 @TotalTime            float,
  135.                 @ElapsedTime        int,
  136.                 @ElapsedHours      int,
  137.                 @ElapsedMinutes smallint,
  138.                 @OrderDateOpened        datetime,
  139.                 @TestKeyID            int,
  140.                 @AutoOpenOrder  bit,
  141.                 @CountOfLogs        int,
  142.                 @DefaultOpenStatus      varchar(50),
  143.                 @Junk         int,
  144.                 @Junk2    float,
  145.                 @TotalHours          int,
  146.                 @TotalMinutes      int,
  147.                 @DateClosed          datetime,
  148.                 @LogReasonLaborRate     money
  149.  
  150. /*  Return Codes
  151.  
  152.         0 = Successful Add
  153.         1 = Missing SO Number
  154.         2 = Invalid SO Number
  155.         3 = Missing Start DateTime
  156.         6 = Have End Date but no Log Reason
  157.         7 = End Date/Time < Start Date/Time
  158.         8 = Missing/Invalid Rep
  159.         9 = Invalid Log Reason
  160.              10 = No Log End Date and SO is closed
  161.                 11 = Have Actual Time but no End date/time
  162. */
  163.  
  164. -- initialize return variables
  165. SET @SOLogKeyID = 0
  166. SET @ReturnCode = 0
  167. SET @LogReasonLaborRate = 0
  168.  
  169. If @LaborRate Is Null SET @LaborRate = 0
  170. IF @ActualHours is Null SET @ActualHours = 0
  171. IF @ActualMinutes is Null SET @ActualMinutes = 0
  172.  
  173. -- make sure SO # passed in
  174. IF @SONumber = 0
  175.       BEGIN
  176.         SET @ReturnCode = 1          -- missing SO#
  177.         RETURN
  178.       END
  179.  
  180. SET @TestKeyID = Null
  181.  
  182. -- make sure SO # is valid and get AccountNumber, Contract Number and Date Opened
  183. SELECT @TestKeyID = SONumber, @AccountNumber = AccountNumber,
  184.         @ContractNumber = ContractNumber, @OrderDateOpened = DateOpened,
  185.         @DateClosed = DateClosed
  186.         FROM tblServiceOrders WHERE SONumber = @SONumber
  187.  
  188. IF @TestKeyID is Null      -- Record not found
  189.       BEGIN
  190.         SET @ReturnCode = 2          -- Invalid SO #
  191.         RETURN
  192.       END
  193.  
  194. IF @StartDateTime = 'Dec 30 1899 12:00AM' or @StartDateTime = '' or @StartDateTime = 0 or @StartDateTime is Null
  195.        BEGIN       
  196.         SET @ReturnCode = 3          -- missing start date
  197.         RETURN 
  198.        END
  199.  
  200. IF @ContractNumber is Null SET @ContractNumber = 0
  201.  
  202. IF @EndDateTime = 'Dec 30 1899 12:00AM' or @EndDateTime = '' or @EndDateTime = 0 or @EndDateTime is Null
  203.        BEGIN        -- no end date passed in
  204.         -- if Service Order is closed, they can't have a log without an end date/time
  205.         IF @DateClosed is Not Null
  206.               BEGIN
  207.                 SET @ReturnCode = 10        -- SO Closed but log has no end date
  208.                 RETURN
  209.               END
  210.  
  211.         IF @ActualHours > 0 OR @ActualMinutes > 0
  212.               BEGIN
  213.                 SET @ReturnCode = 11        -- Have actual time but no end date
  214.                 RETURN
  215.               END
  216.  
  217.         SET @EndDateTime = Null
  218.         SET @ActualHours = 0
  219.         SET @ActualMinutes = 0
  220.         SET @ElapsedHours = 0
  221.         SET @ElapsedMinutes = 0
  222.         SET @TotalUnits = 0
  223.        END
  224. ELSE       -- have an end date/time
  225.       BEGIN
  226.         IF @LogReason is Null or @LogReason = ''
  227.                BEGIN       
  228.                 SET @ReturnCode = 6          -- have an end date/time but no Log Reason
  229.                 RETURN
  230.                END
  231.  
  232.         -- make sure End date is not < Start date
  233.         IF @EndDateTime < @StartDateTime
  234.                BEGIN
  235.                 SET @ReturnCode = 7          -- End date/time < start date/time
  236.                 RETURN
  237.                END
  238.       END
  239.  
  240. IF @RepNumber = 0            
  241.        BEGIN
  242.         SET @ReturnCode = 8          -- missing rep number
  243.         RETURN 
  244.        END
  245.  
  246. -- make sure it's a valid rep
  247. SET @TestKeyID = Null
  248.  
  249. SELECT @TestKeyID = RepNumber FROM tblReps
  250.         WHERE RepNumber = @RepNumber
  251.  
  252. IF @TestKeyID is Null      
  253.       BEGIN
  254.         SET @ReturnCode = 8          -- invalid rep number
  255.         RETURN
  256.       END
  257.  
  258. -- calculate elapsed time
  259. IF @EndDateTime is not Null
  260.       BEGIN
  261.         SET @ElapsedTime =  datediff(mi, @StartDateTime, @EndDateTime)
  262.         SET @ElapsedHours = cast(@ElapsedTime / 60 as int)
  263.         SET @ElapsedMinutes = @ElapsedTime - (@ElapsedHours * 60)
  264.       END
  265. ELSE
  266.       BEGIN
  267.         SET @ElapsedHours = 0
  268.         SET @ElapsedMinutes = 0
  269.       END
  270.  
  271. SET @UnitFactor = 0          -- initialize
  272.  
  273. IF @LogReason is not Null and @LogReason <> ''
  274. -- make sure log reason is valid and get unit factor
  275.       BEGIN
  276.         SET @Reason = Null
  277.         SELECT @Reason =  LogReason, @UnitFactor = UnitFactor, @LogReasonLaborRate = StandardRate FROM tblLogReasons
  278.                 WHERE  LogReason = @LogReason
  279.        
  280.         IF @Reason is Null     
  281.               BEGIN
  282.                 SET @ReturnCode = 9          -- invalid log reason
  283.                 RETURN
  284.               END
  285.        END
  286.  
  287. IF @LogReasonLaborRate is Null SET @LogReasonLaborRate = 0
  288.  
  289. -- get total time as a decimal
  290. SET @TotalTime = @ActualHours + (@ActualMinutes / 60.0)
  291.  /*  NOTE: Must use 60.0 so that the devisor is not an integer otherwise, if both dividend and devisor
  292.       are integers, the result will be an integer  */
  293. IF @TotalTime > 0
  294.       BEGIN
  295.         SET @TotalUnits = @TotalTime * @UnitFactor
  296.       END
  297. ELSE  SET @TotalUnits =  0
  298.  
  299. IF @LaborRate = 0 SET @LaborRate = @LogReasonLaborRate
  300.  
  301. INSERT INTO tblSOLogs
  302.                 (AccountNumber,
  303.                  SONumber,
  304.                  StartDateTime,
  305.                  EndDateTime,
  306.                  LogComment,
  307.                  TimeLogReason,
  308.                  Tech,
  309.                  LogHours,
  310.                  LogMinutes,
  311.                  ElapsedHours,
  312.                  ElapsedMinutes,
  313.                  Billable,
  314.                  Chargable,
  315.                  ContractNumber,
  316.                  UnitFactor,
  317.                  TotalUnits,
  318.                  Mileage,
  319.                  Tolls,
  320.                  Meals,
  321.                  MiscExpenses,
  322.                  Fuel,
  323.                  Parking,
  324.                  Accomodations,
  325.                 LogReasonLaborRate)
  326.         VALUES
  327.                     (@AccountNumber,
  328.                 @SONumber,
  329.                 @StartDateTime,
  330.                 @EndDateTime,
  331.                 @LogComment,
  332.                 @LogReason,
  333.                 @RepNumber,
  334.                 @ActualHours,
  335.                 @ActualMinutes,
  336.                 @ElapsedHours,
  337.                 @ElapsedMinutes,
  338.                 @Billable,
  339.                 @Chargable,
  340.                 @ContractNumber,
  341.                 @UnitFactor,
  342.                 @TotalUnits,
  343.                 @Mileage,
  344.                 @Tolls,
  345.                 @Meals,
  346.                 @MiscExpenses,
  347.                 @Fuel,
  348.                 @Parking,
  349.                 @Accomodations,
  350.                 @LaborRate)
  351. -- Return the key id to test the success of the insert.
  352. SET @SOLogKeyID = @@Identity
  353.  
  354. IF @OrderDateOpened is Null     -- If the order is not already open
  355.       BEGIN
  356.         --  check system value to see if first log opens the ticket
  357.         SELECT @AutoOpenOrder = AutoOpenOrder FROM tblSysSOSettings
  358.  
  359.         IF @AutoOpenOrder = 1      -- first log opens order
  360.               BEGIN     
  361.                 -- see if this is the first log
  362.                 SELECT @CountOfLogs = COUNT(SOLogKeyID)   FROM tblSOLogs
  363.                         WHERE SONumber = @SONumber
  364.  
  365.                 IF @CountOfLogs = 1          -- this is the first log
  366.                       BEGIN          
  367.                         -- get the default open SO status
  368.                         SELECT @DefaultOpenStatus = DefaultOpenOrderStatus
  369.                                 FROM tblSysSOSettings
  370.  
  371.                         -- Get received time of order and make sure start of log is after the received date
  372.  
  373.                         -- open the so with the log start date/time and default open order status
  374.                         UPDATE tblServiceOrders
  375.                                 SET DateOpened = convert(varchar(25),@StartDateTime, dbo.tf_GetDateFormat()),  TimeOpened =  convert(varchar(25),@StartDateTime, 8),
  376.                                                 Status = @DefaultOpenStatus, StatusChangedIndicator = 1
  377.                                 WHERE SONumber = @SONumber
  378.                       END
  379.               END
  380.       END
  381.  
  382. -- if there is a contract number, see if it is an hourly or units basis and update the contract
  383. IF @ContractNumber > 0
  384.        BEGIN
  385.         SET @Basis = Null
  386.         SELECT @Basis = Basis FROM tblContracts WHERE ContractNumber = @ContractNumber
  387.  
  388.         IF @Basis =  'U' or @Basis = 'H'
  389.               BEGIN
  390.                 EXEC tsp_AdjustContractTime @ContractNumber
  391.               END
  392.        END
  393.  
  394. SET @Junk = 0      -- we don't need some of the values returned
  395. SET @Junk2 = 0
  396. SET @TotalHours = 0
  397. SET @TotalMinutes = 0
  398.  -- get total time logged against the ticket
  399. EXEC tsp_TallySOLogs @SONumber, 0,
  400.         @Junk output, @Junk output, @Junk output, @Junk output,
  401.         @Junk output, @Junk output, @TotalHours output, @TotalMinutes output,
  402.         @Junk2 output, @Junk2 output, @Junk2 output, @Junk2 output
  403.  
  404.  
  405. -- Now update the SO for the new total time logged
  406. UPDATE tblServiceOrders SET TotalHours = @TotalHours, TotalMinutes = @TotalMinutes
  407.         WHERE SONumber = @SONumber

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right
worth-right