function setPunchData($data) { //Debug::Arr($data, 'punchDataArray', __FILE__, __LINE__, __METHOD__,10); /* <b>TimeTrexSoapServer::setPunchData()</b>: Data: <pre> array(10) { ["date_stamp"]=> string(9) "05-Nov-05" ["transfer"]=> int(0) ["branch_id"]=> string(1) "0" ["time_stamp"]=> string(7) "4:42 PM" ["user_date_id"]=> string(5) "14774" ["punch_control_id"]=> string(5) "26614" ["type_id"]=> string(2) "10" ["department_id"]=> string(1) "0" ["status_id"]=> string(2) "20" ["user_id"]=> string(1) "1" } </pre><br> */ //Debug::Arr($data, ' Data: ', __FILE__, __LINE__, __METHOD__,10); //User prefs should be set before we parse the date/time. $punch_full_time_stamp = TTDate::parseDateTime($data['date_stamp'] . ' ' . $data['time_stamp']); Debug::Text(' Punch Full TimeStamp: ' . date('r' . $punch_full_time_stamp) . ' (' . $punch_full_time_stamp . ') TimeZone: ' . $this->getUserObject()->getUserPreferenceObject()->getTimeZone(), __FILE__, __LINE__, __METHOD__, 10); $pf = new PunchFactory(); $pf->StartTransaction(); //Set User before setTimeStamp so rounding can be done properly. $pf->setUser($this->getUserObject()->getId()); if (isset($data['transfer']) and $data['transfer'] == 1) { Debug::Text(' Enabling Transfer!: ', __FILE__, __LINE__, __METHOD__, 10); $data['type_id'] = 10; $data['status_id'] = 10; $pf->setTransfer(TRUE); } $pf->setType($data['type_id']); $pf->setStatus($data['status_id']); $pf->setTimeStamp($punch_full_time_stamp); if (isset($data['status_id']) and $data['status_id'] == 20 and isset($data['punch_control_id']) and $data['punch_control_id'] != '') { $pf->setPunchControlID($data['punch_control_id']); } else { $pf->setPunchControlID($pf->findPunchControlID()); } $pf->setStation($this->getStationObject()->getId()); if ($pf->isNew()) { $pf->setActualTimeStamp($punch_full_time_stamp); $pf->setOriginalTimeStamp($pf->getTimeStamp()); } if ($pf->isValid() == TRUE) { $return_date = $pf->getTimeStamp(); if ($pf->getStatus() == 10) { $label = 'In'; } else { $label = 'Out'; } if ($pf->Save(FALSE) == TRUE) { $pcf = new PunchControlFactory(); $pcf->setId($pf->getPunchControlID()); $pcf->setPunchObject($pf); if (isset($data['branch_id']) and $data['branch_id'] != '') { $pcf->setBranch($data['branch_id']); } if (isset($data['department_id']) and $data['department_id'] != '') { $pcf->setDepartment($data['department_id']); } if (isset($data['job_id']) and $data['job_id'] != '') { $pcf->setJob($data['job_id']); } if (isset($data['job_item_id']) and $data['job_item_id'] != '') { $pcf->setJobItem($data['job_item_id']); } if (isset($data['quantity']) and $data['quantity'] != '') { $pcf->setQuantity($data['quantity']); } if (isset($data['bad_quantity']) and $data['bad_quantity'] != '') { $pcf->setBadQuantity($data['bad_quantity']); } //Don't overwrite note if a new one isn't set. This makes it more difficult to delete a note if they want to, //But thats better then accidently deleting it. if (isset($data['note']) and $data['note'] != '') { $pcf->setNote($data['note']); } if (isset($data['other_id1']) and $data['other_id1'] != '') { $pcf->setOtherID1($data['other_id1']); } if (isset($data['other_id2']) and $data['other_id2'] != '') { $pcf->setOtherID2($data['other_id2']); } if (isset($data['other_id3']) and $data['other_id3'] != '') { $pcf->setOtherID3($data['other_id3']); } if (isset($data['other_id4']) and $data['other_id4'] != '') { $pcf->setOtherID4($data['other_id4']); } if (isset($data['other_id5']) and $data['other_id5'] != '') { $pcf->setOtherID5($data['other_id5']); } //$pcf->setEnableStrictJobValidation( TRUE ); $pcf->setEnableCalcUserDateID(TRUE); $pcf->setEnableCalcTotalTime(TRUE); $pcf->setEnableCalcSystemTotalTime(TRUE); $pcf->setEnableCalcUserDateTotal(TRUE); $pcf->setEnableCalcException(TRUE); $pcf->setEnablePreMatureException(TRUE); //Enable pre-mature exceptions at this point. if ($pcf->isValid() == TRUE) { Debug::Text(' Punch Control is valid, saving...: ', __FILE__, __LINE__, __METHOD__, 10); if ($pcf->Save(TRUE, TRUE) == TRUE) { //Force isNew() lookup. Debug::text('Return Date: ' . $return_date, __FILE__, __LINE__, __METHOD__, 10); $retval = '<div style="font-size:28px; font-weight: bold"> <table> <tr> <td>' . $this->getUserObject()->getFullName() . '</td> </tr> <tr> <td> Punch ' . $label . ': ' . TTDate::getDate('TIME', $return_date) . ' </td> </tr> </table> </div>'; Debug::text('RetVal: ' . $retval, __FILE__, __LINE__, __METHOD__, 10); //Set stations last punch time stamp so we can filter out duplicates later on. //$pf->FailTransaction(); $pf->CommitTransaction(); return $retval; } else { Debug::text('Punch Control save failed!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Punch Control is NOT VALID!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Punch save failed!', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Punch is NOT VALID: ', __FILE__, __LINE__, __METHOD__, 10); } $pf->FailTransaction(); Debug::text('Returning FALSE: Action Failed! ', __FILE__, __LINE__, __METHOD__, 10); //Get text errors to display to the user. $errors = NULL; if (isset($pf) and is_object($pf)) { $errors .= $pf->Validator->getErrors(); } if (isset($pcf) and is_object($pcf)) { $errors .= $pcf->Validator->getErrors(); } $errors = wordwrap($errors, 40, "<br>\n"); $retval = '<table bgcolor="red"> <tr> <td style="font-size:28px; font-weight: bold">Action Failed!</td> </tr> <tr> <td style="font-size:14px; font-weight: bold"> ' . $errors . ' </td> </tr> </table>'; return $retval; //return FALSE; }