Exemplo n.º 1
0
 public static function createGL($hdr, $dtls = [])
 {
     $blc = 0.0;
     foreach ($dtls as $row) {
         $blc += $row['ammount'];
     }
     if ($blc != 0) {
         throw new UserException('GL Balance Failed');
     }
     $gl = new GlHeader();
     $gl->gl_date = $hdr['date'];
     $gl->id_reff = $hdr['id_reff'];
     $gl->type_reff = $hdr['type_reff'];
     $gl->description = $hdr['description'];
     $gl->id_branch = $hdr['id_branch'];
     /*
      * Edited By Mujib Masyhudi
      * on 2014-07-07
      */
     $active_periode = self::getCurrentIdAccPeriode();
     $gl->id_periode = $active_periode['id_periode'];
     $gl->status = 0;
     if (!$gl->save()) {
         throw new UserException(implode("\n", $gl->getFirstErrors()));
     }
     foreach ($dtls as $row) {
         $glDtl = new GlDetail();
         $glDtl->id_gl = $gl->id_gl;
         $glDtl->id_coa = $row['id_coa'];
         $glDtl->amount = $row['ammount'];
         if (!$glDtl->save()) {
             throw new UserException(implode("\n", $glDtl->getFirstErrors()));
         }
     }
 }