use utf8;
package CLMApp::Schema::Result::Customer;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

CLMApp::Schema::Result::Customer

=cut

use strict;
use warnings;

use base 'DBIx::Class::Core';

=head1 COMPONENTS LOADED

=over 4

=item * L<DBIx::Class::InflateColumn::DateTime>

=back

=cut

__PACKAGE__->load_components("InflateColumn::DateTime");

=head1 TABLE: C<Customer>

=cut

__PACKAGE__->table("Customer");

=head1 ACCESSORS

=head2 customerid

  data_type: 'integer'
  is_auto_increment: 1
  is_nullable: 0

=head2 customernumber

  data_type: 'varchar'
  is_nullable: 0
  size: 100

=head2 amphireid

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 distributorcompanyid

  data_type: 'integer'
  is_nullable: 0

=head2 distributorwarehouseid

  data_type: 'integer'
  is_nullable: 0

=head2 chaingroupid

  data_type: 'integer'
  is_nullable: 0

=head2 chainconceptid

  data_type: 'integer'
  is_nullable: 0

=head2 chainunitid

  data_type: 'integer'
  is_nullable: 0

=head2 ownership

  data_type: 'varchar'
  is_nullable: 1
  size: 200

=head2 customerunitnumber

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 unitname

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 address

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 city

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 state

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 zip

  data_type: 'varchar'
  is_nullable: 1
  size: 100

=head2 orderguideflagid

  data_type: 'integer'
  default_value: 3
  is_nullable: 1

=head2 comments

  data_type: 'longtext'
  is_nullable: 1

=head2 setupdate

  data_type: 'datetime'
  datetime_undef_if_invalid: 1
  is_nullable: 0

=head2 lastchangeddate

  data_type: 'datetime'
  datetime_undef_if_invalid: 1
  is_nullable: 0

=head2 lastupdatedbyid

  data_type: 'integer'
  is_nullable: 0

=head2 statusid

  data_type: 'integer'
  default_value: 2
  is_nullable: 1

=head2 ownership2

  data_type: 'varchar'
  is_nullable: 1
  size: 200

=head2 groupname

  data_type: 'varchar'
  is_nullable: 1
  size: 200

=head2 longitude

  data_type: 'decimal'
  default_value: 0.00000000
  is_nullable: 0
  size: [15,8]

=head2 latitude

  data_type: 'decimal'
  default_value: 0.00000000
  is_nullable: 0
  size: [15,8]

=head2 distancetodistcenter

  data_type: 'decimal'
  default_value: 0.00000000
  is_nullable: 0
  size: [15,8]

=head2 countrycode

  data_type: 'char'
  is_nullable: 0
  size: 3

=head2 brandedprocurement

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 active

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 brandedprocurementdeleted

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 opstatus

  data_type: 'varchar'
  is_nullable: 1
  size: 255

=head2 opstatusdate

  data_type: 'varchar'
  is_nullable: 1
  size: 255

=head2 bpflagdate

  data_type: 'datetime'
  datetime_undef_if_invalid: 1
  default_value: '0000-00-00 00:00:00'
  is_nullable: 1

=head2 ownershiptype

  data_type: 'varchar'
  is_nullable: 1
  size: 255

=head2 invoicesystem

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 ordersystem

  data_type: 'integer'
  default_value: 0
  is_nullable: 1
=head2 opendate

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 setupbyid

  data_type: 'integer'
  default_value: 0
  is_nullable: 0

=cut

__PACKAGE__->add_columns(
  "customerid",
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
  "customernumber",
  { data_type => "varchar", is_nullable => 0, size => 100 },
  "amphireid",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "distributorcompanyid",
  { data_type => "integer", is_nullable => 0 },
  "distributorwarehouseid",
  { data_type => "integer", is_nullable => 0 },
  "chaingroupid",
  { data_type => "integer", is_nullable => 0 },
  "chainconceptid",
  { data_type => "integer", is_nullable => 0 },
  "chainunitid",
  { data_type => "integer", is_nullable => 0 },
  "ownership",
  { data_type => "varchar", is_nullable => 1, size => 200 },
  "customerunitnumber",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "unitname",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "address",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "city",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "state",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "zip",
  { data_type => "varchar", is_nullable => 1, size => 100 },
  "orderguideflagid",
  { data_type => "integer", default_value => 3, is_nullable => 1 },
  "comments",
  { data_type => "longtext", is_nullable => 1 },
  "setupdate",
  {
    data_type => "datetime",
    datetime_undef_if_invalid => 1,
    is_nullable => 0,
  },
  "lastchangeddate",
  {
    data_type => "datetime",
    datetime_undef_if_invalid => 1,
    is_nullable => 0,
  },
  "lastupdatedbyid",
  { data_type => "integer", is_nullable => 0 },
  "statusid",
  { data_type => "integer", default_value => 2, is_nullable => 1 },
  "ownership2",
  { data_type => "varchar", is_nullable => 1, size => 200 },
  "groupname",
  { data_type => "varchar", is_nullable => 1, size => 200 },
  "longitude",
  {
    data_type => "decimal",
    default_value => "0.00000000",
    is_nullable => 0,
    size => [15, 8],
  },
  "latitude",
  {
    data_type => "decimal",
    default_value => "0.00000000",
    is_nullable => 0,
    size => [15, 8],
  },
  "distancetodistcenter",
  {
    data_type => "decimal",
    default_value => "0.00000000",
    is_nullable => 0,
    size => [15, 8],
  },
  "countrycode",
  { data_type => "char", is_nullable => 0, size => 3 },
  "brandedprocurement",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "active",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "brandedprocurementdeleted",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "opstatus",
  { data_type => "varchar", is_nullable => 1, size => 255 },
  "opstatusdate",
  { data_type => "varchar", is_nullable => 1, size => 255 },
  "bpflagdate",
  {
    data_type => "datetime",
    datetime_undef_if_invalid => 1,
    default_value => "0000-00-00 00:00:00",
    is_nullable => 1,
  },
  "ownershiptype",
  { data_type => "varchar", is_nullable => 1, size => 255 },
  "invoicesystem",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "ordersystem",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "marketid",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "email",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "emailgov",
  { data_type => "tinyint", default_value => 0, is_nullable => 1 },
  "opfstatus",
  { data_type => "tinyint", default_value => 0, is_nullable => 1 },
  "accountingcode",
  { data_type => "varchar", is_nullable => 1, size => 255 },
  "filecode",
  { data_type => "varchar", is_nullable => 1, size => 255 },
  "routingid",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "entitytypeid",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "storestatusdate",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "storestatus",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "opendate",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "setupbyid",
  { data_type => "integer", default_value => 0, is_nullable => 0 },
);

=head1 PRIMARY KEY

=over 4

=item * L</customerid>

=back

=cut

__PACKAGE__->set_primary_key("customerid");

=head1 UNIQUE CONSTRAINTS

=head2 C<CustomerNumberDistributorWarehouseID>

=over 4

=item * L</customernumber>

=item * L</distributorwarehouseid>

=back

=cut

__PACKAGE__->add_unique_constraint(
  "CustomerNumberDistributorWarehouseID",
  ["customernumber", "distributorwarehouseid"],
);

# {"address":"21001 TATUM BLVD","amphireid":"110400","backofficesys":"1","chainconcept":"1044181","chaingroup":"1010015","chainparent":"","city":"PHOENIX","comments":"","countrycode":"USA","customerid":"9712","customernumber":"0002830","customerunitnumber":"","distancetodistcenter":"22.2","distributorcompany":"116","distributorwarehouse":"02","dmaprogrammanagerid":"0","dmavpid":"0","groupname":"","lastchangeddate":"1900-01-01 00:00:00","lastinvdate":"1900-01-01 00:00:00","lastupdatedbyid":"3","latitude":"33.6759492","longitude":"-111.9746167","orderguideflagid":"0","ownership":"","ownership2":"","ownershipid":"0","setupdate":"1900-01-01 00:00:00","state":"AZ","statusid":"2","unitname":"JILLIAN'S PHOENIX PRODUCE","zip":"8505"}

__PACKAGE__->belongs_to(
  "country",
  "CLMApp::Schema::Result::Country",
  { "foreign.countrycode" => "self.countrycode" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "orderflag",
  "CLMApp::Schema::Result::OrderFlag",
  { "foreign.id" => "self.orderguideflagid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "distributor",
  "CLMApp::Schema::Result::DistributorCompany",
  { "foreign.distributorcompanyid" => "self.distributorcompanyid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

# __PACKAGE__->belongs_to(
#   "programmanager",
#   "CLMApp::Schema::Result::DmaprogramManager",
#   { "foreign.dmaprogrammanagerid" => "self.dmaprogrammanagerid" },
#   { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
# );

# __PACKAGE__->belongs_to(
#   "vp",
#   "CLMApp::Schema::Result::Dmavp",
#   { "foreign.dmavpid" => "self.dmavpid" },
#   { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
# );

__PACKAGE__->belongs_to(
  "chaingrp",
  "CLMApp::Schema::Result::ChainGroup",
  { "foreign.chaingroupid" => "self.chaingroupid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "warehouse",
  "CLMApp::Schema::Result::DistributorWarehouse",
  {"foreign.distributorwarehouseid" => "self.distributorwarehouseid"},
  # [{ "foreign.distributorlocid" => "self.distributorwarehouse",
  #  "foreign.parentid" => "self.distributorcompany" }], # AND = 1 hash, OR = multiple
  { is_deferrable => 1, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);


__PACKAGE__->belongs_to(
  "concept",
  "CLMApp::Schema::Result::ChainConcept",
  { "foreign.chainconceptid" => "self.chainconceptid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "status",
  "CLMApp::Schema::Result::Status",
  { "foreign.id" => "self.statusid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left'},
);

# __PACKAGE__->belongs_to(
#   "backofficesystemcustomers",
#   "CLMApp::Schema::Result::BackOfficeSystemCustomer",
#   { "foreign.customerid" => "self.customerid" },
#   { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
# );

# __PACKAGE__->many_to_many(
#   "backofficesystemcustomer" => "backoffice_customer", "backofficesystemcustomer"
# );

__PACKAGE__->belongs_to(
  "user",
  "CLMApp::Schema::Result::User",
  { "foreign.user_id" => "self.lastupdatedbyid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

# Created by DBIx::Class::Schema::Loader v0.07039 @ 2017-05-06 14:53:22
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:AGo3/RLEZN7zhwRNajaA6Q

__PACKAGE__->belongs_to(
  "setupbyid",
  "CLMApp::Schema::Result::User",
  { "foreign.user_id" => "self.setupbyid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);


__PACKAGE__->has_many(
  "back_office_system_customers",
  "CLMApp::Schema::Result::BackOfficeSystemCustomer",
  { "foreign.customerid" => "self.customerid" },
  { cascade_copy => 0, cascade_delete => 0 },
);


__PACKAGE__->many_to_many(
  "systems" => "back_office_system_customers", "system"
);

__PACKAGE__->belongs_to(
  "backofficesystemcustomer",
  "CLMApp::Schema::Result::BackOfficeSystemCustomer",
  { customerid => "customerid" },
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
);


__PACKAGE__->belongs_to(
  "chainunit",
  "CLMApp::Schema::Result::ChainUnit",
  { "foreign.chainunitid" => "self.chainunitid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "ordersystems",
  "CLMApp::Schema::Result::OrderInvoiceSystem",
   sub {
      my $args = shift;

      return {
        "$args->{foreign_alias}.ordersystem" =>  { '=' => 1},
        "$args->{foreign_alias}.id" => { -ident => "$args->{self_alias}.ordersystem" },
        "$args->{foreign_alias}.deleted"   => { '=' => 0 },
      };
    },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'LEFT' },
);

__PACKAGE__->belongs_to(
  "invoicesystems",
  "CLMApp::Schema::Result::OrderInvoiceSystem",
   sub {
      my $args = shift;

      return {
        "$args->{foreign_alias}.invoicesystem" =>  { '=' => 1},
        "$args->{foreign_alias}.id" => { -ident => "$args->{self_alias}.invoicesystem" },
        "$args->{foreign_alias}.deleted"   => { '=' => 0 },
      };
    },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'LEFT' },
);


__PACKAGE__->belongs_to(
  "market",
  "CLMApp::Schema::Result::Market",
  { "foreign.marketid" => "self.marketid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'LEFT' },
);

__PACKAGE__->belongs_to(
  "distributor",
  "CLMApp::Schema::Result::DistributorCompany",
  { "foreign.distributorcompanyid" => "self.distributorcompanyid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'LEFT' },
);

__PACKAGE__->belongs_to(
  "routing",
  "CLMApp::Schema::Result::Routing",
  { "foreign.routingid" => "self.routingid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->has_many(
  "systems_customer",
  "CLMApp::Schema::Result::CustomerSystem",
  { "foreign.customerid" => "self.customerid" },
  { cascade_copy => 0, cascade_delete => 0 },
);

__PACKAGE__->has_many(
  "customersystem",
  "CLMApp::Schema::Result::CustomerSystem",
   sub {
      my $args = shift;
      return {
        "$args->{foreign_alias}.customerid" => { -ident => "$args->{self_alias}.customerid" },
        "$args->{foreign_alias}.deleted"   => { '=' => 0 },
      };
    },  
  # { "foreign.customerid" => "self.customerid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->has_many(
  "customercomment",
  "CLMApp::Schema::Result::CustomerComment`",
  { "foreign.customerid" => "self.customerid" },
  { cascade_copy => 0, cascade_delete => 0 },
);

# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
