Advertisement
IdlaNier97

Untitled

Jun 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Sts\WebToko\BO;
  4.  
  5. use Sts\PleafCore\BusinessFunction;
  6. use Sts\PleafCore\DefaultBusinessFunction;
  7. use Sts\PleafCore\CoreException;
  8. use Sts\PleafCore\Util\ValidationUtil;
  9.  
  10. use DB;
  11. use Log;
  12.  
  13. /**
  14. * @author
  15. * @in
  16. *   - doc_type_id
  17. *   - doc_date
  18. *   - tenant_id
  19. * @out
  20. *   - []
  21. *
  22. */
  23.  
  24. class ValDocDateMaxBackDate implements BusinessFunction {
  25.  
  26.     public function getDescription(){
  27.         return "Check doc_date Max Back Date";
  28.     }
  29.  
  30.     public function execute($dto){
  31.         // Log::debug($dto);
  32.  
  33.         $doc_type_id = $dto["doc_type_id"];
  34.         $doc_date = $dto["doc_date"];
  35.         $tenant_id = $dto["tenant_id"];
  36.  
  37.         $query = " SELECT f_get_value_system_config_by_param_code ( :tenant_id, 'BACKDATE.LIMIT') ";
  38.  
  39.         $params = [
  40.             "tenant_id" => $tenant_id
  41.         ];
  42.  
  43.         $max_back_date = DB::SELECT($query, $params)[0]->f_get_value_system_config_by_param_code;
  44.  
  45.         $now = time();
  46.         $year = date("Y", $now);
  47.         $month = date("m", $now);
  48.         $day = date("d", $now);
  49.  
  50.         $now = mktime(0,0,0,$month,$day,$year);
  51.  
  52.         $mnl_back_date = $now - ONE_DAY * $max_back_date;
  53.  
  54.         $input =  date_parse_from_format("Ymd", $doc_date);
  55.         $doc_date_in_time = mktime( 0,0,0, $input['month'], $input['day'], $input['year']);
  56.  
  57.         if($doc_date_in_time < $mnl_back_date){
  58.             throw new CoreException(ERROR_BACK_DATE_VALIDATION,[],
  59.             ["doc_date" => ["Tanggal back date maksimal ".$max_back_date." hari."]]);
  60.         }
  61.  
  62.         return [];
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement