Class: SAFT::V2::HTML::LinesTable

Inherits:
Object
  • Object
show all
Defined in:
lib/saft/v2/html.rb

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ LinesTable



419
420
421
# File 'lib/saft/v2/html.rb', line 419

def initialize(lines)
  @lines = lines
end

Instance Method Details

#to_tubbyObject



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/saft/v2/html.rb', line 423

def to_tubby
  Tubby.new { |t|
    t.table {
      t.thead {
        t.tr {
          t.th("RecordID")
          t.th("AccountID")
          t.th("Analysis")
          t.th("ValueDate")
          t.th("Description")
          t.th("Dedit Amount", class: "text-right")
          t.th("Credit Amount", class: "text-right")
          t.th("Rest")
        }
      }

      t.tbody {
        @lines.each { |line|
          t.tr {
            t.td(line.record_id)
            t.td {
               = t.(line.)
              t.div(title: .title) { t << line. }
            }

            t.td {
              line.analyses&.each do |line_analysis|
                analysis = t.get_analysis(
                  line_analysis.analysis_id,
                  line_analysis.analysis_type,
                )
                t.div(title: analysis.title) { t << analysis.link { t << "#{line_analysis.analysis_type} #{line_analysis.analysis_id}" } }
              end
            }
            t.td(line.value_date)
            t.td(line.description)
            t.td(line.debit_amount&.amount, class: "text-right")
            t.td(line.credit_amount&.amount, class: "text-right")
            t.td {
              t.div(class: "mb-2 pl-2 border-l-2") {
                if line.customer_id
                  customer = t.get_customer(line.customer_id)
                  t.div(title: customer.title) {
                    t.strong("Customer ")
                    t << line.customer_id
                    t << " #{customer.name}"
                  }
                end

                if line.supplier_id
                  supplier = t.get_supplier(line.supplier_id)
                  t.div(title: supplier.title) {
                    t.strong("Supplier ")
                    t << line.supplier_id
                    t << " #{supplier.name}"
                  }
                end

                t <<
                  RenderHash.new(
                    line
                      .attributes
                      .except(
                        :record_id,
                        :account_id,
                        :customer_id,
                        :supplier_id,
                        :analyses,
                        :value_date,
                        :description,
                        :debit_amount,
                        :credit_amount,
                      ),
                  )
              }
            }
          }
        }
      }
    }
  }
end