-- =====================================================================
-- Migration: bukanmain  ->  colorindochemtrainertia (63) structure   ** FASTER REVISION **
-- Generated 2026-08-13. REGENERATED 2026-08-14 against `bukanmain2.sql` and re-verified
-- end-to-end. See "WHAT CHANGED ON 2026-08-14" below before reading anything else.
--   source : two db/bukanmain2.sql  (MariaDB 10.4, the STAGING/PRODUCTION database)
--            ⚠ NOT `bukanmain.sql`. That dump came from a replica on which `php artisan
--            migrate` had already run, so it carried 8 tables production does not have.
--            DO NOT regenerate anything from it.
--   target : the LIVE `colorindochemtrainertia` database (MySQL 8.4, DEVELOPMENT).
--            ⚠ NOT `cci_63.sql` alone: that dump was taken 2026-08-13 09:49 and is STALE --
--            it predates migrations 2026_08_13_100300 / _100400 / _100500, all of which have
--            since run on dev. Every difference in this script was re-derived from the live
--            database. The 9 dump-vs-live differences map exactly to those three migrations;
--            there is no unexplained drift.
--
-- ---------------------------------------------------------------------
-- WHAT CHANGED ON 2026-08-14, AND WHY IT MATTERED
--
-- The previous revision was built by comparing `bukanmain.sql` against `cci_63.sql`. That
-- comparison was sound for 254 of 255 table-sets but wrong about one thing, and the one thing
-- was fatal: `bukanmain.sql` had been dumped from a replica that had ALREADY been through
-- `php artisan migrate`. It therefore contained `cache`, `cache_locks`, `failed_jobs`,
-- `job_batches`, `jobs`, `migrations`, `notification` and `sessions`. The diff saw them on both
-- sides, concluded there was nothing to do, and this script created none of them.
--
-- Production has never had a migration run against it and has none of the 8. The result was
-- `Base table or view not found: ...sessions` -- recorded at the time as an operator error. It
-- was not. It was this script.
--
-- PROVEN, not assumed: `bukanmain2.sql` and `bukanmain.sql` are byte-identical across all 254
-- shared CREATE TABLE statements and all 7 views. Those 8 tables are their ONLY difference.
-- So everything the previous revision worked out about the 244 shared tables still holds, and
-- has been re-verified empirically rather than taken on trust (see below).
--
-- Changes in this revision:
--   * NEW SECTION 2b creates the 8 tables. Criterion 6: all 8 are necessary.
--   * NEW SECTION 9 seeds `migrations` with 27 rows so `php artisan migrate` afterwards is a
--     short, guarded pass instead of a replay of everything. FOUR migrations are deliberately
--     NOT seeded because each does real work this script cannot -- see section 9.
--   * SECTION 0's `ALTER DATABASE` no longer names a database.
--   * Section 2's table census corrected: the gap is 67, not 59. The 55 skipped tables were
--     re-derived from scratch; verdict unchanged, but two of the old justifications were wrong.
--
-- HOW THIS REVISION WAS VERIFIED (2026-08-14):
--   `bukanmain2.sql` was loaded into a scratch database, this entire script was run against it,
--   and the result was diffed against the live 63 database. 0 errors. The ONLY remaining
--   differences were: `vehiclestatus.ID` auto_increment (deliberate, see below), the two
--   `quotation` pagination indexes (created by artisan -- see section 9), 50 foreign keys whose
--   endpoints are on skipped tables or are the two provably-wrong PaymentTerm keys, and the 3
--   production-only legacy tables this script leaves alone. Nothing else.
--
-- 63 is DEVELOPMENT. bukanmain is STAGING and PRODUCTION, and the Laravel + Inertia app will
-- run against it. That is why this script is conservative about what it introduces and refuses
-- to remove anything.
--
-- ACCEPTANCE CRITERIA (user, 2026-08-13). bukanmain is the SOURCE OF TRUTH:
--   1. Foreign keys are the ONE exempt subject.
--   2. Everything else follows bukanmain.
--   3. Changes to bukanmain are ADDITIVE ONLY, except the data cleanup foreign keys require.
--   4. Primary keys follow bukanmain.
--   5. bukanmain has it and 63 does not  -> artisan migration adds it to 63.
--   6. 63 has it and bukanmain does not  -> into this script ONLY if necessary; otherwise 63
--                                           keeps it, recorded as deliberate.
--   7. Same thing, different shape       -> follow bukanmain; 63 moves by artisan migration.
--
-- WHAT MOVED TO THE 63 SIDE INSTEAD OF HAPPENING HERE (all are artisan migrations):
--   2026_08_13_100000_widen_remark_columns_to_text            41 remark columns, varchar -> text
--   2026_08_13_100100_restructure_country_to_int_pk_with_code `country` rebuilt on legacy shape
--   2026_08_13_100200_repoint_salesrebateinvoice_status_fks…  GH #260, wrong lookup table
--   2026_08_13_100300_add_legacy_only_columns                 the 4 columns section 3c used to DROP
--   2026_08_13_100400_widen_decimals_to_match_legacy_precisi… the 4 decimals section 3d narrowed
--   2026_08_13_100500_relax_depname_to_match_legacy           the column section 4b tightened
--   2026_08_14_100100_narrow_quotation_decimals_to_match_le…  the 3 decimals section 3d
--                                                             OVERFLOWED on production
--
-- DELIBERATE EXCLUSIONS (63 quirks treated as damage, not intent):
--   * `vehiclestatus`.`ID` keeps its AUTO_INCREMENT (63 has none). It is a fixed 3-row lookup.
--     ⚠ Strictly this is the one place the script does not satisfy criterion 5 (bukanmain has
--     it, 63 does not -> artisan migration for 63). It is the ONLY column-level difference left
--     after this script runs. Raised for a decision rather than settled silently.
--   * quotation.idx_quotation_isdeleted_id and .._tanggal_id are INVISIBLE in 63; MariaDB 10.4
--     cannot express that, so this script does not create them.
--     ⚠⚠ THIS ONLY WORKS BECAUSE SECTION 9 DOES NOT SEED
--     `2026_08_01_100000_add_quotation_list_indexes`. That migration detects MariaDB and creates
--     both indexes WITHOUT the keyword, and it self-guards on information_schema, so artisan
--     adds them safely afterwards. If someone ever "tidies" section 9 by seeding all 31
--     migrations, these two indexes are never created by anything: the paginator COUNT on the
--     Quotation list goes back to a clustered scan (measured on 10k rows: 2.6 MB instead of
--     40 KB) on every request, and nothing errors to tell you.
--   * The one `DROP INDEX` in this file (section 7, `visitplan`.`VisitPlanStatusID`) is NOT a
--     narrowing, despite appearances. bukanmain carries TWO identical 7-column composites on
--     that table (`VisitPlanStatusID` and `VisitPlanStatusID_2`); the statement re-cuts the
--     first to 1 column while `_2` keeps the composite, and section 7 adds a third. Verified on
--     the scratch run: the 7-column composite is present TWICE afterwards. Nothing is lost, so
--     criterion 3 ("additive only") is satisfied in effect.
--   * AUTO_INCREMENT counters are never copied (data-dependent).
--   * The 3 tables and 1 view bukanmain has and 63 does not are left ALONE:
--     `salesrebatedetails`, `salesrebatedetailshistory`, `salesrebatehistory`, view `vwvisitplan`.
--     `salesrebatedetails` (16 columns) is a superseded generation of `salesrebatedetail`
--     (55 columns); bukanmain carries both. Nothing here drops a table (ATURAN ABSOLUT #1).
--   * 63's view `vwijin` is not created here. The 6 shared views differ only in DEFINER.
--   * Section 9 (3 index drops) was REMOVED: not additive, and each was an exact duplicate of a
--     surviving index anyway, so keeping them costs write time only.
--
-- >>> TAKE A FULL BACKUP BEFORE RUNNING. Sections 5 and 6 modify data. <<<
-- >>> RUN audit_bukanmain_before_migrate.sql FIRST. It only reads. <<<
-- >>> THE SCRIPT IS NOT RESUMABLE. DDL implicit-commits and ADD INDEX / ADD CONSTRAINT fail on
--     a second run. A run that dies leaves a half-migrated schema whose only clean recovery is
--     that backup. Sections 5 and 6 are the exception: they are one transaction.
-- >>> RUN IT WITHOUT `--force`. THIS MATTERS MORE THAN IT LOOKS. <<<
--     Without --force the client stops at the first error and the server rolls back the open
--     transaction when the connection closes, which is what makes sections 4c/5/6 all-or-nothing.
--     WITH --force, execution continues past a failure inside that transaction and still reaches
--     the COMMIT, committing a partially applied data cleanup -- precisely the state the
--     transaction exists to prevent. Measured: a forced re-run of this whole file against an
--     already-migrated database returns rc=0 and leaves `migrations` holding 54 rows instead of
--     27. A clean run without --force stops safely at the first CREATE TABLE in section 2.
-- =====================================================================
-- The session mode is COMPUTED, not appended, and it does two opposite things on purpose.
-- Restored from @OLD_SQL_MODE at the end of the file.
--
--   + STRICT_TRANS_TABLES is FORCED ON.
--     Everything this script and the audit promise about failing loudly depends on it. Without
--     it the decimal conversions in section 3d do not abort on an out-of-range value; they CLAMP,
--     silently. Measured: decimal(20,2) -> decimal(20,10) turned 99999999999.00 into
--     9999999999.9999999999, no error, with a warning the mysql client never prints.
--     An earlier revision merely DEMANDED this of the operator and refused to run otherwise.
--     That was the wrong call -- the script can simply set it, and setting it is what makes the
--     promise true rather than aspirational.
--
--   - NO_ZERO_DATE and NO_ZERO_IN_DATE are FORCED OFF, for the WHOLE run.
--     bukanmain is a legacy database written for years under a non-strict server, so its date and
--     datetime columns hold '0000-00-00'. Under NO_ZERO_DATE, ANY ALTER that rebuilds such a
--     table re-validates those rows and fails with ERROR 1292 -- not just the two columns section
--     3b adds, but every charset and decimal conversion on every table that carries a legacy zero
--     date. Measured on a table holding one '0000-00-00' row: with NO_ZERO_DATE a plain
--     latin1->utf8mb4 MODIFY aborts; without it the same statement succeeds and the zero date is
--     preserved unchanged.
--     This is not a licence to write new zero dates -- it is what lets EXISTING ones survive a
--     table copy. 63 holds the same values (19 of 21 purchaseorder.BLDate rows), so preserving
--     them is what makes the two databases match.
--
--   + NO_AUTO_VALUE_ON_ZERO, as before.
--
-- The REPLACE order matters only in that neither name is a substring of the other; both orders
-- work. Empty list elements left behind by REPLACE are tolerated -- verified, the resulting mode
-- reads back as a clean list.
    REPLACE(REPLACE(@@SQL_MODE, 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', ''),
    ',NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES'
);
-- FOREIGN_KEY_CHECKS is ON for the whole run EXCEPT section 8, which turns it off and back
-- on again around the ADD CONSTRAINT block. That exception is what lets InnoDB add the
-- constraints in place instead of copying 154 tables to re-validate rows section B has
-- already cleaned. The protection it used to provide is not dropped, it MOVED: section 7b
-- asserts zero orphans across all 651 relationships and aborts before section 8 runs.
-- Read section 7b before changing any of this.


-- ---------------------------------------------------------------------
-- PRE-FLIGHT ASSERTION - sql_mode
-- The SET above already forces the mode this script needs, so in normal operation both SELECTs
-- below simply print and the run continues. This is a belt-and-braces assertion, not a demand on
-- the operator: it catches the case where the SET did not take effect -- a server that refuses
-- STRICT_TRANS_TABLES, a proxy or connector that rewrites the session mode, or someone editing
-- the SET above without understanding what depends on it.
--
-- Both lines print unconditionally, on purpose. The effective mode belongs in the run log
-- whatever happens; "no output" is the wrong way to report the setting the whole run rests on.
--
-- If STRICT_TRANS_TABLES is somehow still absent, the else-branch subquery returns two rows,
-- which is ERROR 1242 "Subquery returns more than 1 row" -- an abort, and it happens BEFORE the
-- first mutating statement (the ALTER DATABASE in section 0). Nothing is changed. Verified both
-- ways on MySQL 8.4, and observed for real on 2026-08-13 against a MariaDB/XAMPP bukanmain whose
-- server mode was NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION -- no STRICT. The abort is
-- what sent us back to look, and it is why the SET above now forces the mode instead of hoping.
-- ---------------------------------------------------------------------
-- ⚠ ONE UNVERIFIED ASSUMPTION, AND IT IS CHEAP TO SETTLE (2026-08-14).
-- The IF() below returns a deliberately TWO-ROW subquery on its false branch, so that an absent
-- STRICT_TRANS_TABLES raises ERROR 1242 "Subquery returns more than 1 row" -- an abort before
-- the first mutating statement. Both directions were reproduced on MySQL 8.4, which
-- short-circuits IF() and never evaluates the untaken branch.
-- The history matters: the abort that fired on the real MariaDB server on 2026-08-13 was the
-- FALSE branch, back when this script only DEMANDED strict mode. Now that the SET above FORCES
-- it, the condition is always true on a real run -- so the branch that has NEVER been exercised
-- on MariaDB is the only one that will execute. If MariaDB's optimizer folds that constant
-- two-row subquery during optimization rather than short-circuiting, this aborts every time.
-- The failure is SAFE (nothing has changed yet) but would look exactly like the 2026-08-13
-- incident and waste a maintenance window.
-- BEFORE CUTOVER: paste the two SELECTs below into a MariaDB session on their own. One second.
-- If they abort, delete this assertion -- the SET above already guarantees what it checks.
SELECT @@SQL_MODE AS sql_mode_in_effect;
SELECT IF(@@SQL_MODE LIKE '%STRICT_TRANS_TABLES%',
          'sql_mode OK - proceeding',
          (SELECT 'ABORT: STRICT_TRANS_TABLES is NOT set - out-of-range values would be clamped silently'
           UNION ALL
           SELECT 'The SET at the top of this file should have set it. Find out what un-set it before re-running.')
       ) AS preflight_sql_mode;

-- ---------------------------------------------------------------------
-- =====================================================================
-- WHAT THIS REVISION CHANGES, AND WHY IT IS THE SAME MIGRATION
--
-- Generated 2026-08-15 from migrate_bukanmain_to_63.sql by a script, not by hand. Every
-- clause below is COPIED from that file; nothing here was retyped or invented. The end
-- state is intended to be byte-identical, and that was checked by running BOTH files
-- against identical copies of bukanmain2 and diffing the resulting schemas.
--
-- The original ran for about 12 hours on production. It was correct -- it finished with no
-- errors -- but it did far more work than the end state requires. Three things cost the time:
--
--   1. TABLES WERE REBUILT TWO TO FOUR TIMES EACH. Sections 3b/3d/3e/4 and 7 each opened
--      their own ALTER on the same table. 809 ALTER statements touched only 155 distinct
--      tables. InnoDB rebuilds the whole table for a nullability change, so a table in
--      three of those sections was copied three times to reach one end state.
--
--   2. SECTION 7 BUILT 637 INDEXES ONE STATEMENT AT A TIME, each one scanning and sorting
--      the table again -- immediately after section 4 had already rebuilt that same table.
--
--   3. SECTION 8 FORCED ALGORITHM=COPY. With FOREIGN_KEY_CHECKS on, InnoDB cannot add a
--      foreign key in place; it copies the table and validates every row. 154 more full
--      table copies, on top of everything above.
--
-- WHAT IS DIFFERENT HERE
--
--   A. ONE ALTER PER TABLE. Sections 3b, 3d, 3e, 4 and 7 are merged into a single
--      ALTER TABLE per table -- 809 statements become 155. Each table is rebuilt ONCE and
--      its indexes are built during that rebuild instead of by 637 later statements.
--      Checked before merging: across all of 3a/3b/3d/3e/4/7, NO column receives more than
--      one definition clause, so the merge cannot drop or reorder a definition. Clause
--      order within each table is the original section order (3b, 3d, 3e, 4, 7), which is
--      what keeps every ADD COLUMN ... AFTER positioned exactly as before.
--      Section 3a is deliberately NOT merged: it renames users.username -> Username, and
--      section 3b then adds a column AFTER `Password`. Renaming and referencing the new
--      name in one statement is not worth the risk to save one rebuild of one table.
--
--   B. SECTIONS 5 AND 6 MERGED, ONE STATEMENT PER TABLE. They were 1,272 UPDATEs, each a
--      full pass over its table, and they targeted EXACTLY the same 636 columns -- verified,
--      the two column sets are identical with nothing in one and not the other. Merged, a
--      table is passed over once instead of once per foreign-key column:
--          section 5:  WHERE `c` = 0
--          section 6:  WHERE `c` IS NOT NULL AND parent.ID IS NULL
--          merged   :  WHERE `c` IS NOT NULL AND (`c` = 0 OR parent.ID IS NULL)
--      The three cases agree row for row. A row with 0 is nulled whether or not a parent
--      happens to have ID 0 (that is what section 5 meant); an orphan is nulled; a row
--      already NULL is not touched, which the original's own IS NOT NULL guard also did.
--      Order between the two sections never mattered: NO cleanup writes to a column named
--      `ID`, so no parent key set changes while the cleanup runs -- checked, not assumed.
--      No statement carries more than 12 LEFT JOINs; wider tables are split. Every join is a
--      primary-key equality lookup, so no join can multiply rows.
--
--   C. SECTION 8 NO LONGER COPIES 154 TABLES. This is the one change that alters HOW the
--      script protects itself, so it is spelled out. The original left FOREIGN_KEY_CHECKS
--      on precisely so that a row the cleanup missed would abort the run. That protection
--      is kept -- it is simply paid for once, cheaply, instead of 154 times:
--
--        NEW SECTION 7b runs the orphan check EXPLICITLY, as an assertion, over all 651
--        distinct (child, column, parent) relationships the 659 constraints describe. If
--        ANY orphan survives, the script aborts BEFORE creating a single foreign key.
--        Then section 8 creates the constraints with checks off, which lets InnoDB add
--        them in place -- metadata only, no table copy, no re-validation.
--
--      The assertion is WIDER than what it replaces, not narrower. Section 6 cleans 644 of
--      the 659 constraints; the other 15 never had a cleanup at all (14 on
--      budgetandtargetachievements / budgetandtargetreal, which section 2 CREATES EMPTY, and
--      quotationdetails.ItemOriginID, a column section 3b adds as DEFAULT NULL). Those were
--      safe by construction and validated only as a side effect of FOREIGN_KEY_CHECKS. Now
--      they are checked explicitly like everything else.
--
--      ⚠ IF SECTION 7b ABORTS, DO NOT "FIX" IT BY SKIPPING IT. An abort there means a row
--        survived the cleanup, which is a stop-and-look event -- exactly what the original
--        would have hit as ERROR 1452 in section 8, only sooner and naming every offending
--        relationship at once instead of dying at the first table.
--
--   D. FOREIGN_KEY_CHECKS IS OFF FOR SECTION 8 ONLY. It is set back to 1 immediately after,
--      and the file still restores @OLD_FK at the end. Nothing else in the run is exempt.
--
-- WHAT IS DELIBERATELY IDENTICAL: the SQL_MODE computation and its preflight assertion,
-- section 0, section 1, sections 2 and 2b, section 3a, section 4c, the transaction around
-- the data cleanup, both lock timeouts, section 8's constraint list and its grouping, the
-- section 9 seed, and the restore block. Nothing was dropped: the counts are asserted at
-- the bottom of this file's generator, and the A/B schema diff is the real proof.
--
-- EVERY WARNING IN THE ORIGINAL STILL APPLIES -- the backup, running the audit first, NOT
-- resumable, and RUN IT WITHOUT --force.
-- =====================================================================

-- SECTION 0 - Schema default charset
-- Changes no existing table. Without it, any table created on bukanmain AFTERWARDS
-- without an explicit charset inherits the old default and drifts back apart from 63 --
-- latin1 columns that 500 on emoji or CJK. See .claude/rules/column-charset.md.
-- ---------------------------------------------------------------------
-- The database is deliberately NOT NAMED here. `ALTER DATABASE` with the name omitted applies
-- to the database currently selected by the connection, so this script runs correctly whatever
-- the target is called -- `bukanmain`, `bukanmain2`, or the production name. The previous
-- revision hard-coded `bukanmain`, which was already the wrong name for the clean dump and
-- would have silently altered the WRONG database had one by that name existed on the server.
-- Verified accepted and effective on MySQL 8.4; documented identically for MariaDB 10.4
-- ("ALTER {DATABASE | SCHEMA} [db_name] ... if omitted, applies to the default database").
-- PART 0b of the audit prints DATABASE() so the run log records which one it actually was.
ALTER DATABASE DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------
-- SECTION 1 - Table storage engine (0) and table default charset (1)
-- The default charset governs columns added LATER; it does not touch existing columns.
-- The columns of these tables that actually change charset are in section 3d.
-- ---------------------------------------------------------------------
ALTER TABLE `netsuiteinvoicedetail` DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- ---------------------------------------------------------------------
-- SECTION 2 - New tables (4 of the 67 that 63 has and bukanmain lacks)
--
-- ⚠ THE COUNT USED TO SAY 59. That was the fingerprint of the wrong dump: the old
--   `bukanmain.sql` carried 8 Laravel runtime tables the real production database does not
--   have, so the gap looked like 67 - 8 = 59. Against `bukanmain2.sql` it is 67. Section 2b
--   creates those 8; this section creates 4; the remaining 55 stay out.
--
-- 63 is DEVELOPMENT; bukanmain is STAGING and PRODUCTION. Only tables with a proven
-- application code path are introduced to production (user decision 2026-08-13,
-- criterion 6 "provided they are necessary"). The other 55 stay in 63 and are recorded
-- there as deliberate; they are NOT created here. Every one was re-derived from scratch on
-- 2026-08-14 by five independent sweeps, each covering models, DB::table/join/from, raw SQL,
-- concatenated and variable table names, relations, seeders, factories, commands, jobs, mail,
-- routes, Blade and JSX. Verdict: 55 unreachable, 0 must-create. The buckets:
--   * 15 forecast tables. Unreachable because menus 470-479 and 492-499 all carry a blank
--     `LinkLaravel` -- NOT "470-499", which was wrong: 480-491 are Company Category and
--     Pengelolaan CC Web. `User::allowedMenuLinks()` filters `LinkLaravel != ''` and
--     `Menu::navTreeForRole()` prunes blank leaves, so neither the gate nor the sidebar can
--     reach them (.claude/rules/rolemenu-authz.md). ⚠ All 18 rows DO carry live `rolemenu`
--     grants; the blank link is the only thing gating them.
--   * 12 lookups and leftovers: city, province, continent, subdistrict, kodeposrex, insurance,
--     baranglistprice, linkwithother, goodidea, demo, webrouter, user_review. No
--     Province->City->Subdistrict cascade exists anywhere -- every address field is free text.
--     `insurance` is a decoy: all its code hits are the `vehicle`.`Insurance` COLUMN, which is
--     live and must keep working.
--   * 11 carry the (old)/(new)/_2/old suffixes. Every model targets the UNSUFFIXED table, which
--     bukanmain already has. ⚠ TWO exceptions to that framing, both still safe to skip but for
--     a different reason: `(new)companyprojectdetailassignment` has no unsuffixed counterpart
--     anywhere (the live table is `companyprojectdetailsassignment`, with an "s"), and
--     `invoicesalesrebatedetailold` has none either (the live analogue is the differently-worded
--     `salesrebateinvoicedetail`). Do not "restore" either under a name the app never used.
--   * 11 unreferenced islands: nscustomer, nsinvoice, nsinvoicedetail, nsprincipal,
--     nssalesincharge, userchat, usergroupchat, userprincipalgroupdivision, filetable,
--     filetablefield, filetablerows. ⚠ CORRECTION: the five `ns*` tables are NOT on the NetSuite
--     connection -- the `#[Table]` attribute has no `connection` parameter and no model sets
--     `protected $connection`, so they resolve to the DEFAULT connection, i.e. this database.
--     They are skippable because nothing reads them, NOT because they live elsewhere.
--     `netsuiteinvoicedetail` is the counter-example: a main-DB NetSuite mirror that IS live and
--     that bukanmain already has.
--   * 6 rebate/commission: salesrebateinvoicegenerate(+assignment,+status), komisisales
--     (+assignment,+detail). ⚠ Naming trap: the live module "Generate Company Rebate" uses
--     `salesrebateinvoice*`, not `salesrebateinvoicegenerate*`.
--
-- The four created here, and why each is necessary:
--   budgetandtargetachievements  CompanyController::MERGE_TABLES - counted and UPDATEd on merge
--   budgetandtargetreal          same code path
--   nsproduct                    CompanyRebateController - the company-rebates/catalog route
--   quotationitemorigin          FK parent of quotationdetails.ItemOriginID, which section 3b
--                                adds and which is in QuotationDetails::$fillable
--
-- NO 'DROP TABLE IF EXISTS' HERE, deliberately. Their absence from bukanmain is asserted from
-- `bukanmain2.sql` (2026-08-14), not checked at run time. A DROP would discard rows silently;
-- without it the CREATE fails loudly. PARTs 0b and C of the audit tell you in advance.
--
-- FOREIGN KEY clauses are stripped from these CREATEs and re-added in section 8, so creation
-- order cannot matter. The indexes that back those keys are kept here.
--
-- ⚠ THESE FOUR ARRIVE EMPTY. No rows are copied from 63 (user decision: production loads its
--   own data). Two of the four fail in DIFFERENT ways while empty, and one of them fails
--   SILENTLY -- load both before relying on anything that reads them:
--
--   `quotationitemorigin` is a LOOKUP. Until its rows exist, quotationdetails.ItemOriginID can
--     only hold NULL, because section 8 puts a RESTRICT key on it. In 63 that column is
--     populated on 394 of 534 rows, so the feature is live. Writes are REFUSED, loudly.
--
--   `nsproduct` fails QUIETLY, which is worse. CompanyRebateController::catalog() (the method
--     is `catalog()`, at CompanyRebateController.php:507 -- an earlier revision of this comment
--     named a `catalogOptions()` that does not exist) returns HTTP 200 with
--     {"principals":[],"products":[]}. Company Rebate Create then renders with two empty
--     pickers and no error anywhere. 63 holds 2,379 rows.
-- ---------------------------------------------------------------------
CREATE TABLE `budgetandtargetachievements` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL,
  `BudgetAndTargetStatusID` int DEFAULT NULL,
  `Tanggal` datetime NOT NULL,
  `AchievedTarget` datetime NOT NULL,
  `BudgetAndTargetPeriodeID` int DEFAULT NULL,
  `UserIDInput` int DEFAULT NULL,
  `UserIDSales` int DEFAULT NULL,
  `DivisionID` int DEFAULT NULL,
  `CompanyID` int DEFAULT NULL,
  `BarangID` int DEFAULT NULL,
  `QuantityInKG` decimal(20,10) NOT NULL,
  `UnitPriceUSD` decimal(20,10) NOT NULL,
  `UnitPriceIDR` decimal(20,10) NOT NULL,
  `ValueUSD` decimal(20,10) NOT NULL,
  `ValueIDR` decimal(20,10) NOT NULL,
  `Comment` varchar(500) NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `BudgetAndTargetStatusID` (`BudgetAndTargetStatusID`,`BudgetAndTargetPeriodeID`,`UserIDInput`,`UserIDSales`,`DivisionID`,`CompanyID`,`BarangID`),
  KEY `budgetandtargetachievements_BudgetAndTargetPeriodeID` (`BudgetAndTargetPeriodeID`),
  KEY `budgetandtargetachievements_UserIDInput` (`UserIDInput`),
  KEY `budgetandtargetachievements_UserIDSales` (`UserIDSales`),
  KEY `budgetandtargetachievements_DivisionID` (`DivisionID`),
  KEY `budgetandtargetachievements_CompanyID` (`CompanyID`),
  KEY `budgetandtargetachievements_BarangID` (`BarangID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `budgetandtargetreal` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL,
  `BudgetAndTargetStatusID` int DEFAULT NULL,
  `Tanggal` datetime NOT NULL,
  `BudgetAndTargetPeriodeID` int DEFAULT NULL,
  `UserIDInput` int DEFAULT NULL,
  `UserIDSales` int DEFAULT NULL,
  `PrincipalID` int DEFAULT NULL,
  `DivisionID` int DEFAULT NULL,
  `CompanyID` int DEFAULT NULL,
  `QtBudget` decimal(20,5) NOT NULL,
  `QtTarget` decimal(20,5) NOT NULL,
  `UnitPriceUSD` decimal(20,5) NOT NULL,
  `UnitPriceIDR` decimal(20,5) NOT NULL,
  `ValueBudgetUSD` decimal(20,5) NOT NULL,
  `ValueTargetUSD` decimal(20,5) NOT NULL,
  `ValueIDR` decimal(20,5) NOT NULL,
  `Comment` varchar(500) NOT NULL,
  `ASTProductCode` varchar(200) NOT NULL,
  `ASTProductName` varchar(200) NOT NULL,
  `ASTPrincipalCode` varchar(100) NOT NULL,
  `ASTPrincipalName` varchar(100) NOT NULL,
  `QtyBudgetPM` decimal(25,2) NOT NULL,
  `QtyBudgetSM` decimal(25,2) NOT NULL,
  `QtyBudgetMM` decimal(25,2) NOT NULL,
  `QtyTargetPM` decimal(25,2) NOT NULL,
  `QtyTargetSM` decimal(25,2) NOT NULL,
  `QtyTargetMM` decimal(25,2) NOT NULL,
  `UnitPricePM` decimal(25,2) NOT NULL,
  `UnitPriceSM` decimal(25,2) NOT NULL,
  `UnitPriceMM` decimal(25,2) NOT NULL,
  `ValueBudgetUSDPM` decimal(25,2) NOT NULL,
  `ValueBudgetUSDSM` decimal(25,2) NOT NULL,
  `ValueBudgetUSDMM` decimal(25,2) NOT NULL,
  `ValueTargetUSDPM` decimal(25,2) NOT NULL,
  `ValueTargetUSDSM` decimal(25,2) NOT NULL,
  `ValueTargetUSDMM` decimal(25,2) NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `BudgetAndTargetStatusID` (`BudgetAndTargetStatusID`,`BudgetAndTargetPeriodeID`,`UserIDInput`,`UserIDSales`,`DivisionID`,`CompanyID`),
  KEY `PrincipalID` (`PrincipalID`),
  KEY `budgetandtargetreal_BudgetAndTargetPeriodeID` (`BudgetAndTargetPeriodeID`),
  KEY `budgetandtargetreal_UserIDInput` (`UserIDInput`),
  KEY `budgetandtargetreal_UserIDSales` (`UserIDSales`),
  KEY `budgetandtargetreal_DivisionID` (`DivisionID`),
  KEY `budgetandtargetreal_CompanyID` (`CompanyID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `nsproduct` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `isDeleted` int NOT NULL,
  `PrincipalNSCode` varchar(100) NOT NULL,
  `PrincipalNSName` varchar(200) NOT NULL,
  `ProductNSCode` varchar(100) NOT NULL,
  `ProductNSName` varchar(200) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `quotationitemorigin` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL,
  `IsSelected` int NOT NULL,
  `ItemOriginName` varchar(255) NOT NULL,
  `Remark` varchar(255) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- ---------------------------------------------------------------------
-- SECTION 2b - The 8 tables the Laravel runtime needs   (NEW 2026-08-14)
--
-- WHY THIS SECTION EXISTS AT ALL. Every earlier revision of this script was generated against
-- `bukanmain.sql`, a dump taken 2026-08-13 03:34 from a replica on which `php artisan migrate`
-- had ALREADY been run. That replica carried these 8 tables, so the comparison saw them on both
-- sides and this script never created them. The real production database has never had a
-- migration run against it and has none of them. `bukanmain2.sql` (2026-08-14 04:18) is the
-- clean dump. Proven: the two dumps are byte-identical across all 254 shared CREATE TABLE
-- statements, and these 8 tables are their ONLY difference.
--
-- That is why production raised `Base table or view not found: ...sessions`. It was not an
-- operator mistake -- the table genuinely was not there, and this script was why.
--
-- CRITERION 6 ("63 has it and bukanmain does not -> into this script ONLY if necessary").
-- All 8 are necessary, and each for a checkable reason rather than a judgement call:
--
--   sessions       .env SESSION_DRIVER=database. No table -> nobody can log in. This is the
--                  one production actually hit.
--   cache          .env CACHE_STORE=database.
--   cache_locks    same driver; Laravel's database store takes its locks through this table.
--   jobs           .env QUEUE_CONNECTION=database.
--   job_batches    same driver.
--   failed_jobs    same driver; the worker writes here when a job exhausts its retries.
--   migrations     `php artisan migrate` cannot run without it. Section 9 seeds it.
--   notification   a REAL application table, not framework furniture: the in-app notification
--                  inbox behind the header bell (GH #322). Reached by app/Models/Notification.php,
--                  Notifier.php:106 (DB::table('notification')->insert), NotificationController
--                  .php:137, PruneNotifications.php:46/:67, and route notifications.open
--                  (routes/web.php:119).
--
-- SHAPES COME FROM THE LIVE 63 DATABASE (SHOW CREATE TABLE, 2026-08-14), not from cci_63.sql,
-- which is stale. VERIFIED EMPIRICALLY: these 8 CREATEs were run into a scratch database and
-- every resulting SHOW CREATE TABLE is byte-identical to 63's, AUTO_INCREMENT counters aside.
-- For `notification` the shape is also exactly what 2026_08_09_100000_create_notification_table
-- produces, so that migration's tableExists() guard makes the later artisan pass a clean no-op.
--
-- ⚠ `notification` IS latin1 ON PURPOSE. Do not "modernise" it to utf8mb4. Its `LinkLaravel` is
--   compared against `menu`.`LinkLaravel` (latin1) to decide whether the recipient may still open
--   the record; written as a JOIN instead of a bound whereIn, a utf8mb4 copy raises "Illegal mix
--   of collations" -- a runtime 500 on the bell, from a change that looks unrelated. The other 7
--   are utf8mb4/utf8mb4_unicode_ci, which is what Laravel's own migrations produce and what 63
--   has.
--
-- ⚠ SIX OF THESE PIN `ROW_FORMAT=DYNAMIC`, and it is not decoration. `sessions`.`id`,
--   `cache`.`key`, `cache_locks`.`key`, `job_batches`.`id`, `failed_jobs`.`uuid` and
--   `jobs`.`queue` are each varchar(255) utf8mb4 = 1020 bytes of index key, and
--   `failed_jobs_connection_queue_failed_at_index` is 2044. InnoDB allows 3072 under
--   ROW_FORMAT=DYNAMIC but only 767 under COMPACT or REDUNDANT, where every one of them fails
--   with `ERROR 1071 Specified key was too long`. MariaDB 10.4's default
--   `innodb_default_row_format` IS `dynamic` (the default since 10.2.2), so this should never
--   fire -- but `innodb_default_row_format=compact` in a my.ini is the classic
--   Laravel-on-XAMPP failure, and nothing else in this script would tell you in advance.
--   Pinning it costs nothing when the server default already is dynamic. 63's copies are
--   Dynamic too; they simply inherit it rather than spelling it out, so the only difference is
--   the DDL text, not the physical format. `migrations` and `notification` are not pinned --
--   neither has an index key anywhere near the limit.
--
-- ⚠ NO `IF NOT EXISTS`, matching section 2. PART 0b of the audit re-checks their absence against
--   the live server before you run. If one somehow exists, this CREATE fails loudly rather than
--   leaving a table of unknown shape in place -- which is exactly what went wrong the first time.
--
-- ⚠ NONE of the 8 takes part in a foreign key, in either direction, anywhere in 63 (verified
--   against information_schema.KEY_COLUMN_USAGE on the live database). So this section needs no
--   ordering relative to sections 7 and 8, and section 8 adds nothing to these tables.
--
-- ⚠ ALL 8 ARRIVE EMPTY, and here that is correct rather than a caveat: sessions, cache,
--   cache_locks, jobs, job_batches and failed_jobs are runtime scratch Laravel fills itself,
--   `notification` accrues from live events, and `migrations` is filled by section 9.
-- ---------------------------------------------------------------------
CREATE TABLE `sessions` (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` int DEFAULT NULL,
  `ip_address` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `last_activity` int NOT NULL,
  PRIMARY KEY (`id`),
  KEY `sessions_user_id_index` (`user_id`),
  KEY `sessions_last_activity_index` (`last_activity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `cache` (
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` bigint NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_expiration_index` (`expiration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `cache_locks` (
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `owner` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` bigint NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_locks_expiration_index` (`expiration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `queue` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `attempts` smallint unsigned NOT NULL,
  `reserved_at` int unsigned DEFAULT NULL,
  `available_at` int unsigned NOT NULL,
  `created_at` int unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `job_batches` (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `total_jobs` int NOT NULL,
  `pending_jobs` int NOT NULL,
  `failed_jobs` int NOT NULL,
  `failed_job_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `options` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `cancelled_at` int DEFAULT NULL,
  `created_at` int NOT NULL,
  `finished_at` int DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

-- `failed_at` carries an EXPLICIT DEFAULT on purpose. It is the first TIMESTAMP column in the
-- table, and a first TIMESTAMP declared with NEITHER a DEFAULT nor an ON UPDATE is given BOTH
-- automatically. On MariaDB 10.4, where explicit_defaults_for_timestamp is OFF by default, that
-- would silently attach ON UPDATE CURRENT_TIMESTAMP and rewrite failed_at on every UPDATE.
-- Spelling the DEFAULT out suppresses that and reproduces 63 exactly.
CREATE TABLE `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`),
  KEY `failed_jobs_connection_queue_failed_at_index` (`connection`,`queue`,`failed_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `notification` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL DEFAULT 0,
  `UserID` int NOT NULL,
  `EventKey` varchar(60) NOT NULL,
  `Module` varchar(40) NOT NULL,
  `Title` varchar(200) NOT NULL,
  `Message` varchar(500) NOT NULL,
  `LinkLaravel` varchar(200) NOT NULL,
  `RefID` int NOT NULL DEFAULT 0,
  `IsRead` int NOT NULL DEFAULT 0,
  `ReadAt` datetime NULL DEFAULT NULL,
  `Tanggal` datetime NOT NULL,
  `UserIDInput` int NOT NULL DEFAULT 0,
  PRIMARY KEY (`ID`),
  KEY `idx_notification_user_unread` (`UserID`,`IsRead`,`IsDeleted`),
  KEY `idx_notification_user_id` (`UserID`,`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- ---------------------------------------------------------------------
-- SECTION 3a - Renames (2). NOT merged into section A below, on purpose: section 3b adds
-- `PasswordResetToken` AFTER `Password`, a name that only exists once this has run.
-- ---------------------------------------------------------------------
ALTER TABLE `users`
  CHANGE COLUMN `username` `Username` varchar(20) NOT NULL,
  CHANGE COLUMN `password` `Password` varchar(255) NOT NULL;

-- ---------------------------------------------------------------------
-- SECTION A - Columns and indexes, ONE ALTER PER TABLE
--   = the original sections 3b (new columns), 3d (type/charset), 3e (column order),
--     4 (relax 644 columns to NULL) and 7 (supporting indexes), merged per table.
--
--   809 ALTER statements in the original
--   155 here -- each table rebuilt once, its indexes built during that rebuild
--
-- Clause order inside each statement is the original section order, so every
-- ADD COLUMN ... AFTER still lands where it did. InnoDB requires an index on the child
-- column of every foreign key, and those indexes are all created here, well before
-- section 8 needs them.
-- ---------------------------------------------------------------------
ALTER TABLE `branch`
  ADD COLUMN `KodeKecamatan` varchar(200) NOT NULL AFTER `Kecamatan`,
  ADD COLUMN `Kota` varchar(200) NOT NULL AFTER `KodeKecamatan`,
  ADD COLUMN `KodeKota` varchar(200) NOT NULL AFTER `Kota`,
  ADD COLUMN `KodeProvinsi` varchar(200) NOT NULL AFTER `KodeKota`;
ALTER TABLE `company`
  ADD COLUMN `latitude` varchar(20) NOT NULL AFTER `CompanyAddress`,
  ADD COLUMN `longitude` varchar(20) NOT NULL AFTER `latitude`,
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCategoryID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  ADD INDEX `company_BranchID` (`BranchID`),
  ADD INDEX `company_CompanyCategoryID` (`CompanyCategoryID`),
  ADD INDEX `company_DivisionID` (`DivisionID`),
  ADD INDEX `company_UserIDSales` (`UserIDSales`),
  ADD INDEX `IndustryID` (`IndustryID`,`UserIDSales`);
ALTER TABLE `companycp`
  ADD COLUMN `latitude` varchar(20) NOT NULL AFTER `CompanyCPKodePos`,
  ADD COLUMN `longitude` varchar(20) NOT NULL AFTER `latitude`,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL,
  ADD INDEX `companycp_AddressType` (`AddressType`),
  ADD INDEX `CompanyID` (`CompanyID`);
ALTER TABLE `companyproject`
  ADD COLUMN `RemarkSM` varchar(255) NOT NULL AFTER `CommentProject`,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCP` int DEFAULT NULL,
  MODIFY COLUMN `ProjectPriority` int DEFAULT NULL,
  ADD INDEX `companyproject_CompanyCP` (`CompanyCP`),
  ADD INDEX `companyproject_CompanyID` (`CompanyID`),
  ADD INDEX `companyproject_DivisionID` (`DivisionID`),
  ADD INDEX `companyproject_IndustryID` (`IndustryID`),
  ADD INDEX `companyproject_ProjectID` (`ProjectID`),
  ADD INDEX `companyproject_ProjectPriority` (`ProjectPriority`),
  ADD INDEX `companyproject_ProjectStatusID` (`ProjectStatusID`),
  ADD INDEX `companyproject_UserIDInput` (`UserIDInput`),
  ADD INDEX `companyproject_UserIDSales` (`UserIDSales`);
ALTER TABLE `country` ADD COLUMN `country_code` char(2) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL AFTER `country_name`;
ALTER TABLE `menu`
  ADD COLUMN `LinkLaravel` varchar(500) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL AFTER `Link`,
  ADD COLUMN `Icon` varchar(50) DEFAULT NULL AFTER `LinkLaravel`,
  ADD COLUMN `Path` varchar(500) NOT NULL DEFAULT '' AFTER `Icon`,
  MODIFY COLUMN `ParentID` int DEFAULT NULL,
  ADD INDEX `ParentID` (`ParentID`);
ALTER TABLE `purchaseorder`
  ADD COLUMN `PurchasePlanNo` varchar(200) NOT NULL AFTER `Tanggal`,
  ADD COLUMN `PINo` varchar(200) NOT NULL AFTER `PurchasePlanNo`,
  ADD COLUMN `SalesContract` varchar(200) NOT NULL AFTER `PINo`,
  ADD COLUMN `Invoice` varchar(200) NOT NULL AFTER `SalesContract`,
  ADD COLUMN `PrincipalOrigin` varchar(200) NOT NULL AFTER `Invoice`,
  ADD COLUMN `TermOfPayment` varchar(200) NOT NULL AFTER `PrincipalOrigin`,
  ADD COLUMN `SalesTerms` varchar(200) NOT NULL AFTER `TermOfPayment`,
  ADD COLUMN `TaxExemption` varchar(200) NOT NULL AFTER `SalesTerms`,
  ADD COLUMN `PortOfOrigin` varchar(255) NOT NULL AFTER `TaxExemption`,
  ADD COLUMN `PortOfDestination` varchar(255) NOT NULL AFTER `PortOfOrigin`,
  ADD COLUMN `ShipMethod` varchar(255) NOT NULL AFTER `PortOfDestination`,
  ADD COLUMN `ShipInLCLFCL` varchar(200) NOT NULL AFTER `ShipMethod`,
  ADD COLUMN `BLDate` date NOT NULL AFTER `ShipInLCLFCL`,
  MODIFY COLUMN `PurchaseOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  ADD INDEX `purchaseorder_PurchaseOrderStatusID` (`PurchaseOrderStatusID`),
  ADD INDEX `purchaseorder_UserIDInput` (`UserIDInput`);
ALTER TABLE `purchaseorderhargajual`
  ADD COLUMN `HargaJualType` varchar(10) NOT NULL AFTER `UserIDInput`,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  ADD INDEX `purchaseorderhargajual_UserIDInput` (`UserIDInput`);
ALTER TABLE `quotationdetails`
  ADD COLUMN `ItemOriginID` int DEFAULT NULL AFTER `ProjectIDDetails`,
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectIDDetails` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPackID` int DEFAULT NULL,
  MODIFY COLUMN `PackingID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanOrderQty` int DEFAULT NULL,
  ADD INDEX `quotationdetails_ApplicationID` (`ApplicationID`),
  ADD INDEX `quotationdetails_BarangID` (`BarangID`),
  ADD INDEX `quotationdetails_ItemOriginID` (`ItemOriginID`),
  ADD INDEX `quotationdetails_PackingID` (`PackingID`),
  ADD INDEX `quotationdetails_ProjectID` (`ProjectID`),
  ADD INDEX `quotationdetails_ProjectIDDetails` (`ProjectIDDetails`),
  ADD INDEX `quotationdetails_QuotationDetailStatusID` (`QuotationDetailStatusID`),
  ADD INDEX `quotationdetails_QuotationID` (`QuotationID`),
  ADD INDEX `quotationdetails_QuotationPackID` (`QuotationPackID`),
  ADD INDEX `quotationdetails_SatuanID` (`SatuanID`),
  ADD INDEX `quotationdetails_SatuanOrderQty` (`SatuanOrderQty`);
ALTER TABLE `sampleorderdetail`
  ADD COLUMN `IsStockReturnable` int NOT NULL DEFAULT '0' AFTER `SuratJalanDetailID`,
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectIDDetails` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListIDRequest` int DEFAULT NULL,
  MODIFY COLUMN `SuratJalanDetailID` int DEFAULT NULL,
  ADD INDEX `sampleorderdetail_ApplicationID` (`ApplicationID`),
  ADD INDEX `sampleorderdetail_BarangID` (`BarangID`),
  ADD INDEX `sampleorderdetail_BarangListID` (`BarangListID`),
  ADD INDEX `sampleorderdetail_BarangListIDRequest` (`BarangListIDRequest`),
  ADD INDEX `sampleorderdetail_ProjectID` (`ProjectID`),
  ADD INDEX `sampleorderdetail_ProjectIDDetails` (`ProjectIDDetails`),
  ADD INDEX `sampleorderdetail_SampleOrderDetailStatusID` (`SampleOrderDetailStatusID`),
  ADD INDEX `sampleorderdetail_SatuanID` (`SatuanID`),
  ADD INDEX `sampleorderdetail_SuratJalanDetailID` (`SuratJalanDetailID`),
  ADD INDEX `SampleOrderID` (`SampleOrderID`,`SampleOrderDetailStatusID`,`BarangID`,`SatuanID`,`ApplicationID`,`BarangListID`,`SuratJalanDetailID`);
ALTER TABLE `samplerequestimportgoodsreceipt`
  ADD COLUMN `IsRequestList` int NOT NULL AFTER `Keterangan`,
  MODIFY COLUMN `QuantityReceived` decimal(20,5) NOT NULL,
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestImportDetailID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListsID` int DEFAULT NULL,
  ADD INDEX `samplerequestimportgoodsreceipt_BarangID` (`BarangID`),
  ADD INDEX `samplerequestimportgoodsreceipt_BarangListsID` (`BarangListsID`),
  ADD INDEX `samplerequestimportgoodsreceipt_SampleRequestImportDetailID` (`SampleRequestImportDetailID`),
  ADD INDEX `samplerequestimportgoodsreceipt_SatuanID` (`SatuanID`),
  ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestImportDetailID`,`BarangID`,`SatuanID`,`BarangListsID`);
ALTER TABLE `users`
  ADD COLUMN `PasswordResetToken` varchar(255) DEFAULT NULL AFTER `Password`,
  ADD COLUMN `PasswordResetTokenCreatedAt` datetime DEFAULT NULL AFTER `PasswordResetToken`,
  ADD COLUMN `Otp` int NOT NULL AFTER `IsHeadDept`,
  ADD COLUMN `OtpExpiration` datetime NOT NULL AFTER `Otp`,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `RoleID` int DEFAULT NULL,
  MODIFY COLUMN `MaritalStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `HeadID` int DEFAULT NULL,
  ADD INDEX `DepartmentID` (`DepartmentID`,`RoleID`,`MaritalStatusID`,`BranchID`,`HeadID`),
  ADD INDEX `users_BranchID` (`BranchID`),
  ADD INDEX `users_HeadID` (`HeadID`),
  ADD INDEX `users_MaritalStatusID` (`MaritalStatusID`),
  ADD INDEX `users_RoleID` (`RoleID`);
ALTER TABLE `companyhistory`
  MODIFY COLUMN `IndustryID` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  MODIFY COLUMN `CompanyCategoryID` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  ADD INDEX `companyhistory_BranchID` (`BranchID`),
  ADD INDEX `companyhistory_CompanyID` (`CompanyID`),
  ADD INDEX `companyhistory_DivisionID` (`DivisionID`),
  ADD INDEX `companyhistory_UserIDSales` (`UserIDSales`),
  ADD INDEX `UserID` (`UserID`,`CompanyID`,`IndustryID`,`UserIDSales`);
ALTER TABLE `complainassignment`
  MODIFY COLUMN `Comment` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `complainassignment_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complainassignment_UserID` (`UserID`),
  ADD INDEX `ComplainID` (`ComplainID`,`ComplainStatusID`,`UserID`);
ALTER TABLE `complaindetails`
  MODIFY COLUMN `QuantityPacking` decimal(20,5) NOT NULL,
  MODIFY COLUMN `ComplainQuantity` decimal(20,5) NOT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanPackingID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanComplainQuantityID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanUnitPriceUSD` int DEFAULT NULL,
  ADD INDEX `complaindetails_ApplicationID` (`ApplicationID`),
  ADD INDEX `complaindetails_BarangID` (`BarangID`),
  ADD INDEX `complaindetails_ComplainDetailsStatusID` (`ComplainDetailsStatusID`),
  ADD INDEX `complaindetails_PrincipalID` (`PrincipalID`),
  ADD INDEX `complaindetails_SatuanComplainQuantityID` (`SatuanComplainQuantityID`),
  ADD INDEX `complaindetails_SatuanPackingID` (`SatuanPackingID`),
  ADD INDEX `complaindetails_SatuanUnitPriceUSD` (`SatuanUnitPriceUSD`),
  ADD INDEX `ComplainID` (`ComplainID`,`ComplainDetailsStatusID`,`PrincipalID`,`BarangID`,`ApplicationID`,`SatuanPackingID`,`BarangListID`,`SatuanComplainQuantityID`);
ALTER TABLE `netsuiteinvoicedetail`
  MODIFY COLUMN `Quarter` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `CompanyID` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `CompanyName` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `CompanyDivision` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `SalesCustomer` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `SalesTransaction` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemVendor` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemBrand` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemCode` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemName` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `PersenProfit` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `Profitability` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
ALTER TABLE `quotation`
  MODIFY COLUMN `IndustryID` varchar(100) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,
  MODIFY COLUMN `QuotationStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceQuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationSubjectID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationTypeID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationTitleID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryAddressID` int DEFAULT NULL,
  MODIFY COLUMN `InvoiceAddressID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPriceDescID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationSalesTermID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDeliveryTimeID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationValidityID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationStockAvailibilityID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationFeedbackStatusID` int DEFAULT NULL,
  ADD INDEX `quotation_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `quotation_CompanyID` (`CompanyID`),
  ADD INDEX `quotation_DeliveryAddressID` (`DeliveryAddressID`),
  ADD INDEX `quotation_DivisionID` (`DivisionID`),
  ADD INDEX `quotation_InvoiceAddressID` (`InvoiceAddressID`),
  ADD INDEX `quotation_QuotationDeliveryTimeID` (`QuotationDeliveryTimeID`),
  ADD INDEX `quotation_QuotationFeedbackStatusID` (`QuotationFeedbackStatusID`),
  ADD INDEX `quotation_QuotationPaymentTermID` (`QuotationPaymentTermID`),
  ADD INDEX `quotation_QuotationPriceDescID` (`QuotationPriceDescID`),
  ADD INDEX `quotation_QuotationSalesTermID` (`QuotationSalesTermID`),
  ADD INDEX `quotation_QuotationStatusID` (`QuotationStatusID`),
  ADD INDEX `quotation_QuotationStockAvailibilityID` (`QuotationStockAvailibilityID`),
  ADD INDEX `quotation_QuotationSubjectID` (`QuotationSubjectID`),
  ADD INDEX `quotation_QuotationTitleID` (`QuotationTitleID`),
  ADD INDEX `quotation_QuotationTypeID` (`QuotationTypeID`),
  ADD INDEX `quotation_QuotationValidityID` (`QuotationValidityID`),
  ADD INDEX `quotation_ReferenceQuotationID` (`ReferenceQuotationID`),
  ADD INDEX `quotation_UserIDInput` (`UserIDInput`),
  ADD INDEX `quotation_UserIDSales` (`UserIDSales`);
ALTER TABLE `salesrebatedetail`
  MODIFY COLUMN `Recipient` varchar(500) NOT NULL,
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  ADD INDEX `salesrebatedetail_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `salesrebatedetail_SalesRebateID` (`SalesRebateID`);
ALTER TABLE `suratjalan`
  MODIFY COLUMN `Vendor` varchar(200) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `LocationID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDsales` int DEFAULT NULL,
  MODIFY COLUMN `UserIDCreatorSJ` int DEFAULT NULL,
  ADD INDEX `SampleOrderID` (`SampleOrderID`,`DeliveryID`,`CompanyID`,`CompanyCPID`,`LocationID`,`UserIDsales`,`UserIDCreatorSJ`),
  ADD INDEX `suratjalan_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `suratjalan_CompanyID` (`CompanyID`),
  ADD INDEX `suratjalan_DeliveryID` (`DeliveryID`),
  ADD INDEX `suratjalan_LocationID` (`LocationID`),
  ADD INDEX `suratjalan_UserIDCreatorSJ` (`UserIDCreatorSJ`),
  ADD INDEX `suratjalan_UserIDsales` (`UserIDsales`);
ALTER TABLE `budgetandtarget`
  MODIFY COLUMN `UnitPricePM` decimal(25,2) NOT NULL AFTER `QtyTargetMM`,
  MODIFY COLUMN `UnitPriceSM` decimal(25,2) NOT NULL AFTER `UnitPricePM`,
  MODIFY COLUMN `UnitPriceMM` decimal(25,2) NOT NULL AFTER `UnitPriceSM`,
  MODIFY COLUMN `ValueBudgetUSDPM` decimal(25,2) NOT NULL AFTER `UnitPriceMM`,
  MODIFY COLUMN `ValueBudgetUSDSM` decimal(25,2) NOT NULL AFTER `ValueBudgetUSDPM`,
  MODIFY COLUMN `ValueBudgetUSDMM` decimal(25,2) NOT NULL AFTER `ValueBudgetUSDSM`,
  MODIFY COLUMN `ValueTargetUSDPM` decimal(25,2) NOT NULL AFTER `ValueBudgetUSDMM`,
  MODIFY COLUMN `ValueTargetUSDSM` decimal(25,2) NOT NULL AFTER `ValueTargetUSDPM`,
  MODIFY COLUMN `ValueTargetUSDMM` decimal(25,2) NOT NULL AFTER `ValueTargetUSDSM`,
  MODIFY COLUMN `BudgetAndTargetStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BudgetAndTargetPeriodeID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  ADD INDEX `budgetandtarget_BudgetAndTargetPeriodeID` (`BudgetAndTargetPeriodeID`),
  ADD INDEX `budgetandtarget_CompanyID` (`CompanyID`),
  ADD INDEX `budgetandtarget_DivisionID` (`DivisionID`),
  ADD INDEX `budgetandtarget_UserIDInput` (`UserIDInput`),
  ADD INDEX `budgetandtarget_UserIDSales` (`UserIDSales`);
ALTER TABLE `application`
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  ADD INDEX `application_DivisionID` (`DivisionID`),
  ADD INDEX `GroupDivisionID` (`GroupDivisionID`,`DivisionID`);
ALTER TABLE `bank`
  MODIFY COLUMN `QuotationPriceDescID` int DEFAULT NULL,
  ADD INDEX `bank_QuotationPriceDescID` (`QuotationPriceDescID`);
ALTER TABLE `bankdivision`
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `BankID` int DEFAULT NULL,
  ADD INDEX `bankdivision_BankID` (`BankID`),
  ADD INDEX `DivisionID` (`DivisionID`),
  ADD INDEX `DivisionID_2` (`DivisionID`,`BankID`);
ALTER TABLE `barang`
  MODIFY COLUMN `CategoryID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `TypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `barang_PrincipalID` (`PrincipalID`),
  ADD INDEX `barang_SatuanID` (`SatuanID`),
  ADD INDEX `barang_TypeID` (`TypeID`),
  ADD INDEX `CategoryID` (`CategoryID`,`PrincipalID`);
ALTER TABLE `baranglist`
  MODIFY COLUMN `BarangListStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailID` int DEFAULT NULL,
  ADD INDEX `baranglist_BarangID` (`BarangID`),
  ADD INDEX `baranglist_SampleOrderDetailID` (`SampleOrderDetailID`),
  ADD INDEX `baranglist_SatuanID` (`SatuanID`),
  ADD INDEX `BarangListStatusID` (`BarangListStatusID`,`BarangID`,`SatuanID`,`SampleOrderDetailID`);
ALTER TABLE `baranglists`
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `BarangID` (`BarangID`,`SatuanID`),
  ADD INDEX `baranglists_SatuanID` (`SatuanID`);
ALTER TABLE `barangstockmin`
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `BarangID` (`BarangID`,`SatuanID`),
  ADD INDEX `barangstockmin_SatuanID` (`SatuanID`);
ALTER TABLE `budgetandtargetassignment`
  MODIFY COLUMN `BudgetAndTargetID` int DEFAULT NULL,
  MODIFY COLUMN `BudgetAndTargetStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `budgetandtargetassignment_BudgetAndTargetStatusID` (`BudgetAndTargetStatusID`),
  ADD INDEX `budgetandtargetassignment_UserID` (`UserID`);
ALTER TABLE `comissionpercentage`
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  ADD INDEX `comissionpercentage_PrincipalID` (`PrincipalID`);
ALTER TABLE `companyaccessothers`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  ADD INDEX `companyaccessothers_CompanyID` (`CompanyID`),
  ADD INDEX `UserID` (`UserID`,`CompanyID`);
ALTER TABLE `companycategory`
  MODIFY COLUMN `GroupDivID` int DEFAULT NULL,
  ADD INDEX `companycategory_GroupDivID` (`GroupDivID`);
ALTER TABLE `companycategorylist`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCategoryID` int DEFAULT NULL,
  ADD INDEX `companycategorylist_CompanyCategoryID` (`CompanyCategoryID`),
  ADD INDEX `companycategorylist_CompanyID` (`CompanyID`);
ALTER TABLE `companycpassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL,
  ADD INDEX `companycpassignment_AddressType` (`AddressType`),
  ADD INDEX `companycpassignment_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `companycpassignment_CompanyID` (`CompanyID`),
  ADD INDEX `UsersID` (`UsersID`,`CompanyCPID`,`CompanyID`);
ALTER TABLE `companyindustry`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  ADD INDEX `companyindustry_CompanyID` (`CompanyID`),
  ADD INDEX `companyindustry_IndustryID` (`IndustryID`);
ALTER TABLE `companyproduct`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `CCPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CCBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CCVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CCPriceSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPriceSatuanID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`,`DivisionID`,`ApplicationID`,`CCPrincipalID`,`CCBarangID`,`CCVolumeSatuanID`,`CCPriceSatuanID`,`CompetitorPrincipalID`,`CompetitorBarangID`,`CompetitorVolumeSatuanID`,`CompetitorPriceSatuanID`),
  ADD INDEX `companyproduct_ApplicationID` (`ApplicationID`),
  ADD INDEX `companyproduct_CCBarangID` (`CCBarangID`),
  ADD INDEX `companyproduct_CCPriceSatuanID` (`CCPriceSatuanID`),
  ADD INDEX `companyproduct_CCPrincipalID` (`CCPrincipalID`),
  ADD INDEX `companyproduct_CCVolumeSatuanID` (`CCVolumeSatuanID`),
  ADD INDEX `companyproduct_CompetitorBarangID` (`CompetitorBarangID`),
  ADD INDEX `companyproduct_CompetitorPriceSatuanID` (`CompetitorPriceSatuanID`),
  ADD INDEX `companyproduct_CompetitorPrincipalID` (`CompetitorPrincipalID`),
  ADD INDEX `companyproduct_CompetitorVolumeSatuanID` (`CompetitorVolumeSatuanID`),
  ADD INDEX `companyproduct_DivisionID` (`DivisionID`);
ALTER TABLE `companyproductapplication`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `ProductApplicationID` int DEFAULT NULL,
  ADD INDEX `companyproductapplication_CompanyID` (`CompanyID`),
  ADD INDEX `companyproductapplication_ProductApplicationID` (`ProductApplicationID`);
ALTER TABLE `companyproductassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProductID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `CCPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CCBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CCVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CCPriceSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPriceSatuanID` int DEFAULT NULL,
  ADD INDEX `companyproductassignment_ApplicationID` (`ApplicationID`),
  ADD INDEX `companyproductassignment_CCBarangID` (`CCBarangID`),
  ADD INDEX `companyproductassignment_CCPriceSatuanID` (`CCPriceSatuanID`),
  ADD INDEX `companyproductassignment_CCPrincipalID` (`CCPrincipalID`),
  ADD INDEX `companyproductassignment_CCVolumeSatuanID` (`CCVolumeSatuanID`),
  ADD INDEX `companyproductassignment_CompanyID` (`CompanyID`),
  ADD INDEX `companyproductassignment_CompanyProductID` (`CompanyProductID`),
  ADD INDEX `companyproductassignment_CompetitorBarangID` (`CompetitorBarangID`),
  ADD INDEX `companyproductassignment_CompetitorPriceSatuanID` (`CompetitorPriceSatuanID`),
  ADD INDEX `companyproductassignment_CompetitorPrincipalID` (`CompetitorPrincipalID`),
  ADD INDEX `companyproductassignment_CompetitorVolumeSatuanID` (`CompetitorVolumeSatuanID`),
  ADD INDEX `companyproductassignment_DivisionID` (`DivisionID`),
  ADD INDEX `UsersID` (`UsersID`,`CompanyProductID`,`CompanyID`,`DivisionID`,`ApplicationID`,`CCPrincipalID`,`CCBarangID`,`CCVolumeSatuanID`,`CCPriceSatuanID`,`CompetitorPrincipalID`,`CompetitorBarangID`,`CompetitorVolumeSatuanID`,`CompetitorPriceSatuanID`);
ALTER TABLE `companyproductcategory`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `ProductCategoryID` int DEFAULT NULL,
  ADD INDEX `companyproductcategory_CompanyID` (`CompanyID`),
  ADD INDEX `companyproductcategory_ProductCategoryID` (`ProductCategoryID`);
ALTER TABLE `companyproduction`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `VolumeSatuanID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`,`DivisionID`,`ApplicationID`,`VolumeSatuanID`),
  ADD INDEX `companyproduction_ApplicationID` (`ApplicationID`),
  ADD INDEX `companyproduction_DivisionID` (`DivisionID`),
  ADD INDEX `companyproduction_VolumeSatuanID` (`VolumeSatuanID`);
ALTER TABLE `companyproductionassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProductionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `VolumeSatuanID` int DEFAULT NULL,
  ADD INDEX `companyproductionassignment_ApplicationID` (`ApplicationID`),
  ADD INDEX `companyproductionassignment_CompanyID` (`CompanyID`),
  ADD INDEX `companyproductionassignment_CompanyProductionID` (`CompanyProductionID`),
  ADD INDEX `companyproductionassignment_DivisionID` (`DivisionID`),
  ADD INDEX `companyproductionassignment_VolumeSatuanID` (`VolumeSatuanID`),
  ADD INDEX `UsersID` (`UsersID`,`CompanyProductionID`,`CompanyID`,`DivisionID`,`ApplicationID`,`VolumeSatuanID`);
ALTER TABLE `companyprojectassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectDetailID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectDetailCCID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  ADD INDEX `companyprojectassignment_CompanyProjectDetailCCID` (`CompanyProjectDetailCCID`),
  ADD INDEX `companyprojectassignment_CompanyProjectDetailID` (`CompanyProjectDetailID`),
  ADD INDEX `companyprojectassignment_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectassignment_ProjectStatusID` (`ProjectStatusID`),
  ADD INDEX `companyprojectassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailcc`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemReasonID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeID` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailcc_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetailcc_DetailID` (`DetailID`),
  ADD INDEX `companyprojectdetailcc_ItemReasonID` (`ItemReasonID`),
  ADD INDEX `companyprojectdetailcc_ItemStatusID` (`ItemStatusID`),
  ADD INDEX `companyprojectdetailcc_PriceTypeID` (`PriceTypeID`),
  ADD INDEX `companyprojectdetailcc_PrincipalID` (`PrincipalID`),
  ADD INDEX `companyprojectdetailcc_ProductID` (`ProductID`),
  ADD INDEX `companyprojectdetailcc_ProjectStatusID` (`ProjectStatusID`),
  ADD INDEX `companyprojectdetailcc_QtTypeID` (`QtTypeID`),
  ADD INDEX `companyprojectdetailcc_SatuanID` (`SatuanID`);
ALTER TABLE `companyprojectdetailccassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `DetailCCID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeID` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailccassignment_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetailccassignment_DetailCCID` (`DetailCCID`),
  ADD INDEX `companyprojectdetailccassignment_DetailID` (`DetailID`),
  ADD INDEX `companyprojectdetailccassignment_PriceTypeID` (`PriceTypeID`),
  ADD INDEX `companyprojectdetailccassignment_PrincipalID` (`PrincipalID`),
  ADD INDEX `companyprojectdetailccassignment_ProductID` (`ProductID`),
  ADD INDEX `companyprojectdetailccassignment_QtTypeID` (`QtTypeID`),
  ADD INDEX `companyprojectdetailccassignment_SatuanID` (`SatuanID`),
  ADD INDEX `companyprojectdetailccassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailcomp`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalIDComp` int DEFAULT NULL,
  MODIFY COLUMN `ProductIDComp` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDComp` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailcomp_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetailcomp_DetailID` (`DetailID`),
  ADD INDEX `companyprojectdetailcomp_PriceTypeIDComp` (`PriceTypeIDComp`),
  ADD INDEX `companyprojectdetailcomp_PrincipalIDComp` (`PrincipalIDComp`),
  ADD INDEX `companyprojectdetailcomp_ProductIDComp` (`ProductIDComp`),
  ADD INDEX `companyprojectdetailcomp_QtTypeIDComp` (`QtTypeIDComp`),
  ADD INDEX `companyprojectdetailcomp_SatuanIDComp` (`SatuanIDComp`);
ALTER TABLE `companyprojectdetailcompassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `DetailCompID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalIDComp` int DEFAULT NULL,
  MODIFY COLUMN `ProductIDComp` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDComp` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailcompassignment_CompanyProjectIDID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetailcompassignment_DetailCompID` (`DetailCompID`),
  ADD INDEX `companyprojectdetailcompassignment_DetailID` (`DetailID`),
  ADD INDEX `companyprojectdetailcompassignment_PriceTypeIDComp` (`PriceTypeIDComp`),
  ADD INDEX `companyprojectdetailcompassignment_PrincipalIDComp` (`PrincipalIDComp`),
  ADD INDEX `companyprojectdetailcompassignment_ProductIDComp` (`ProductIDComp`),
  ADD INDEX `companyprojectdetailcompassignment_QtTypeIDComp` (`QtTypeIDComp`),
  ADD INDEX `companyprojectdetailcompassignment_SatuanIDComp` (`SatuanIDComp`),
  ADD INDEX `companyprojectdetailcompassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetails`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `OpportunityGroupID` int DEFAULT NULL,
  ADD INDEX `companyprojectdetails_ApplicationID` (`ApplicationID`),
  ADD INDEX `companyprojectdetails_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetails_OpportunityGroupID` (`OpportunityGroupID`),
  ADD INDEX `companyprojectdetails_ProjectStatusID` (`ProjectStatusID`);
ALTER TABLE `companyprojectdetailsassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `OpportunityGroupID` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailsassignment_ApplicationID` (`ApplicationID`),
  ADD INDEX `companyprojectdetailsassignment_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetailsassignment_DetailID` (`DetailID`),
  ADD INDEX `companyprojectdetailsassignment_OpportunityGroupID` (`OpportunityGroupID`),
  ADD INDEX `companyprojectdetailsassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailstatusassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `DetailCCID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemReasonID` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailstatusassignment_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectdetailstatusassignment_DetailCCID` (`DetailCCID`),
  ADD INDEX `companyprojectdetailstatusassignment_DetailID` (`DetailID`),
  ADD INDEX `companyprojectdetailstatusassignment_ItemReasonID` (`ItemReasonID`),
  ADD INDEX `companyprojectdetailstatusassignment_ItemStatusID` (`ItemStatusID`),
  ADD INDEX `companyprojectdetailstatusassignment_ProjectStatusID` (`ProjectStatusID`),
  ADD INDEX `companyprojectdetailstatusassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailstatusreason`
  MODIFY COLUMN `StatusID` int DEFAULT NULL,
  ADD INDEX `companyprojectdetailstatusreason_StatusID` (`StatusID`);
ALTER TABLE `companyprojectheaderassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCP` int DEFAULT NULL,
  MODIFY COLUMN `ProjectPriority` int DEFAULT NULL,
  ADD INDEX `companyprojectheaderassignment_CompanyCP` (`CompanyCP`),
  ADD INDEX `companyprojectheaderassignment_CompanyID` (`CompanyID`),
  ADD INDEX `companyprojectheaderassignment_CompanyProjectID` (`CompanyProjectID`),
  ADD INDEX `companyprojectheaderassignment_DivisionID` (`DivisionID`),
  ADD INDEX `companyprojectheaderassignment_IndustryID` (`IndustryID`),
  ADD INDEX `companyprojectheaderassignment_ProjectID` (`ProjectID`),
  ADD INDEX `companyprojectheaderassignment_ProjectPriority` (`ProjectPriority`),
  ADD INDEX `companyprojectheaderassignment_UserIDInput` (`UserIDInput`),
  ADD INDEX `companyprojectheaderassignment_UserIDSales` (`UserIDSales`);
ALTER TABLE `complain`
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainTypeID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainReasonID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  ADD INDEX `complain_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `complain_CompanyID` (`CompanyID`),
  ADD INDEX `complain_ComplainReasonID` (`ComplainReasonID`),
  ADD INDEX `complain_ComplainTypeID` (`ComplainTypeID`),
  ADD INDEX `complain_DivisionID` (`DivisionID`),
  ADD INDEX `complain_UserIDInput` (`UserIDInput`),
  ADD INDEX `complain_UserIDSales` (`UserIDSales`),
  ADD INDEX `ComplainStatusID` (`ComplainStatusID`,`ComplainTypeID`,`DivisionID`,`CompanyID`,`CompanyCPID`,`UserIDInput`,`UserIDSales`);
ALTER TABLE `complaindetailsaction`
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `complaindetailsaction_ComplainDetailsID` (`ComplainDetailsID`),
  ADD INDEX `complaindetailsaction_ComplainDetailsStatusID` (`ComplainDetailsStatusID`),
  ADD INDEX `complaindetailsaction_DepartmentID` (`DepartmentID`),
  ADD INDEX `complaindetailsaction_UserID` (`UserID`),
  ADD INDEX `ComplainID` (`ComplainID`,`ComplainDetailsID`,`ComplainDetailsStatusID`,`DepartmentID`,`UserID`);
ALTER TABLE `complaindetailsactionassignment`
  MODIFY COLUMN `ComplainDetailsActionID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `complaindetailsactionassignment_ComplainDetailsID` (`ComplainDetailsID`),
  ADD INDEX `complaindetailsactionassignment_ComplainDetailsStatusID` (`ComplainDetailsStatusID`),
  ADD INDEX `complaindetailsactionassignment_ComplainID` (`ComplainID`),
  ADD INDEX `complaindetailsactionassignment_DepartmentID` (`DepartmentID`),
  ADD INDEX `complaindetailsactionassignment_UserID` (`UserID`),
  ADD INDEX `ComplainDetailsActionID` (`ComplainDetailsActionID`,`ComplainID`,`ComplainDetailsID`,`ComplainDetailsStatusID`,`DepartmentID`,`UserID`);
ALTER TABLE `complaindetailsassignment`
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `complaindetailsassignment_ComplainDetailsID` (`ComplainDetailsID`),
  ADD INDEX `complaindetailsassignment_ComplainDetailsStatusID` (`ComplainDetailsStatusID`),
  ADD INDEX `complaindetailsassignment_DepartmentID` (`DepartmentID`),
  ADD INDEX `complaindetailsassignment_UserID` (`UserID`),
  ADD INDEX `ComplainID` (`ComplainID`,`ComplainDetailsID`,`ComplainDetailsStatusID`,`DepartmentID`,`UserID`);
ALTER TABLE `complainitem`
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainTypeID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  ADD INDEX `complainitem_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complainitem_ComplainTypeID` (`ComplainTypeID`),
  ADD INDEX `complainitem_PrincipalID` (`PrincipalID`),
  ADD INDEX `complainitem_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  ADD INDEX `complainitemassignment_ComplainItemID` (`ComplainItemID`),
  ADD INDEX `complainitemassignment_ComplainItemStatusID` (`ComplainItemStatusID`),
  ADD INDEX `complainitemassignment_DepartmentID` (`DepartmentID`),
  ADD INDEX `complainitemassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemdetails`
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `PackingMonth` int DEFAULT NULL,
  MODIFY COLUMN `PackingYear` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  ADD INDEX `complainitemdetails_ApplicationID` (`ApplicationID`),
  ADD INDEX `complainitemdetails_BarangID` (`BarangID`),
  ADD INDEX `complainitemdetails_CompanyID` (`CompanyID`),
  ADD INDEX `complainitemdetails_ComplainDetailStatusID` (`ComplainDetailStatusID`),
  ADD INDEX `complainitemdetails_ComplainItemID` (`ComplainItemID`),
  ADD INDEX `complainitemdetails_DivisionID` (`DivisionID`),
  ADD INDEX `complainitemdetails_IndustryID` (`IndustryID`),
  ADD INDEX `complainitemdetails_PackingMonth` (`PackingMonth`),
  ADD INDEX `complainitemdetails_PackingYear` (`PackingYear`);
ALTER TABLE `complainitemdetailsaction`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  ADD INDEX `complainitemdetailsaction_ComplainID` (`ComplainID`),
  ADD INDEX `complainitemdetailsaction_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complainitemdetailsaction_DepartmentID` (`DepartmentID`),
  ADD INDEX `complainitemdetailsaction_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemdetailsactionassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  ADD INDEX `complainitemdetailsactionassignment_ComplainItemID` (`ComplainItemID`),
  ADD INDEX `complainitemdetailsactionassignment_ComplainItemStatusID` (`ComplainItemStatusID`),
  ADD INDEX `complainitemdetailsactionassignment_DepartmentID` (`DepartmentID`),
  ADD INDEX `complainitemdetailsactionassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemdetailslot`
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL,
  ADD INDEX `complainitemdetailslot_ComplainItemDetailsID` (`ComplainItemDetailsID`),
  ADD INDEX `complainitemdetailslot_ComplainItemID` (`ComplainItemID`),
  ADD INDEX `complainitemdetailslot_PackagingID` (`PackagingID`);
ALTER TABLE `complainitemdetailslotassignment`
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemDetailsLotID` int DEFAULT NULL,
  MODIFY COLUMN `DepID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL,
  ADD INDEX `complainitemdetailslotassignment_ComplainItemDetailsID` (`ComplainItemDetailsID`),
  ADD INDEX `complainitemdetailslotassignment_ComplainItemDetailsLotID` (`ComplainItemDetailsLotID`),
  ADD INDEX `complainitemdetailslotassignment_ComplainItemID` (`ComplainItemID`),
  ADD INDEX `complainitemdetailslotassignment_DepartmentID` (`DepID`),
  ADD INDEX `complainitemdetailslotassignment_PackagingID` (`PackagingID`);
ALTER TABLE `complaintosupplier`
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainTypeID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemTypeID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PackingMonth` int DEFAULT NULL,
  MODIFY COLUMN `PackingYear` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  ADD INDEX `complaintosupplier_ApplicationID` (`ApplicationID`),
  ADD INDEX `complaintosupplier_CompanyID` (`CompanyID`),
  ADD INDEX `complaintosupplier_ComplainItemTypeID` (`ComplainItemTypeID`),
  ADD INDEX `complaintosupplier_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complaintosupplier_ComplainTypeID` (`ComplainTypeID`),
  ADD INDEX `complaintosupplier_DivisionID` (`DivisionID`),
  ADD INDEX `complaintosupplier_IndustryID` (`IndustryID`),
  ADD INDEX `complaintosupplier_PackingMonth` (`PackingMonth`),
  ADD INDEX `complaintosupplier_PackingYear` (`PackingYear`),
  ADD INDEX `complaintosupplier_PrincipalID` (`PrincipalID`),
  ADD INDEX `complaintosupplier_ProductID` (`ProductID`),
  ADD INDEX `complaintosupplier_UserIDInput` (`UserIDInput`),
  ADD INDEX `complaintosupplier_UserIDSales` (`UserIDSales`);
ALTER TABLE `complaintosupplierassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  ADD INDEX `complaintosupplierassignment_ComplainID` (`ComplainID`),
  ADD INDEX `complaintosupplierassignment_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complaintosupplierassignment_DepartmentID` (`DepartmentID`),
  ADD INDEX `complaintosupplierassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `complaintosupplierdetailsaction`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartementID` int DEFAULT NULL,
  ADD INDEX `complaintosupplierdetailsaction_ComplainID` (`ComplainID`),
  ADD INDEX `complaintosupplierdetailsaction_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complaintosupplierdetailsaction_DepartementID` (`DepartementID`),
  ADD INDEX `complaintosupplierdetailsaction_UserIDInput` (`UserIDInput`);
ALTER TABLE `complaintosupplierdetailsactionassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  ADD INDEX `complaintosupplierdetailsactionassignment_ComplainID` (`ComplainID`),
  ADD INDEX `complaintosupplierdetailsactionassignment_ComplainStatusID` (`ComplainStatusID`),
  ADD INDEX `complaintosupplierdetailsactionassignment_DepartmentID` (`DepartmentID`),
  ADD INDEX `complaintosupplierdetailsactionassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `division`
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL,
  ADD INDEX `GroupDivisionID` (`GroupDivisionID`);
ALTER TABLE `documentgroupdivision`
  MODIFY COLUMN `DocID` int DEFAULT NULL,
  MODIFY COLUMN `GroupDivID` int DEFAULT NULL,
  ADD INDEX `documentgroupdivision_DocID` (`DocID`),
  ADD INDEX `documentgroupdivision_GroupDivID` (`GroupDivID`);
ALTER TABLE `documentupload`
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `DocumentCategoryID` int DEFAULT NULL,
  ADD INDEX `documentupload_DocumentCategoryID` (`DocumentCategoryID`),
  ADD INDEX `PrincipalID` (`PrincipalID`,`DocumentCategoryID`);
ALTER TABLE `documentuploadinternal`
  MODIFY COLUMN `DocumentCategoryID` int DEFAULT NULL,
  ADD INDEX `DocumentCategoryID` (`DocumentCategoryID`);
ALTER TABLE `izin`
  MODIFY COLUMN `IzinTypeID` int DEFAULT NULL,
  MODIFY COLUMN `IzinTypeStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `IzinStatusID` int DEFAULT NULL,
  ADD INDEX `izin_IzinStatusID` (`IzinStatusID`),
  ADD INDEX `izin_IzinTypeStatusID` (`IzinTypeStatusID`),
  ADD INDEX `izin_UserIDInput` (`UserIDInput`),
  ADD INDEX `izin_UserIDSales` (`UserIDSales`),
  ADD INDEX `IzinTypeID` (`IzinTypeID`,`IzinTypeStatusID`,`UserIDInput`,`UserIDSales`,`IzinStatusID`);
ALTER TABLE `izinassignment`
  MODIFY COLUMN `IzinID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `IzinStatusID` int DEFAULT NULL,
  ADD INDEX `izinassignment_IzinStatusID` (`IzinStatusID`),
  ADD INDEX `izinassignment_UserID` (`UserID`),
  ADD INDEX `IzinID` (`IzinID`,`UserID`,`IzinStatusID`);
ALTER TABLE `izintypestatus`
  MODIFY COLUMN `IzinTypeID` int DEFAULT NULL,
  ADD INDEX `IzinTypeID` (`IzinTypeID`);
ALTER TABLE `labworkrequest`
  MODIFY COLUMN `LabWorkRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDProjectInitiator` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestFeedbackStatusID` int DEFAULT NULL,
  ADD INDEX `labworkrequest_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `labworkrequest_CompanyID` (`CompanyID`),
  ADD INDEX `labworkrequest_DivisionID` (`DivisionID`),
  ADD INDEX `labworkrequest_IndustryID` (`IndustryID`),
  ADD INDEX `labworkrequest_LabWorkRequestFeedbackStatusID` (`LabWorkRequestFeedbackStatusID`),
  ADD INDEX `labworkrequest_ProjectID` (`ProjectID`),
  ADD INDEX `labworkrequest_UserIDInput` (`UserIDInput`),
  ADD INDEX `labworkrequest_UserIDProjectInitiator` (`UserIDProjectInitiator`),
  ADD INDEX `labworkrequest_UserIDSales` (`UserIDSales`),
  ADD INDEX `LabWorkRequestStatusID` (`LabWorkRequestStatusID`,`UserIDInput`,`UserIDSales`,`DivisionID`,`CompanyID`,`CompanyCPID`,`LabWorkRequestFeedbackStatusID`);
ALTER TABLE `labworkrequestassignment`
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `labworkrequestassignment_LabWorkRequestStatusID` (`LabWorkRequestStatusID`),
  ADD INDEX `LabWorkRequestID` (`LabWorkRequestID`,`LabWorkRequestStatusID`),
  ADD INDEX `UserID` (`UserID`);
ALTER TABLE `labworkrequestdetails`
  MODIFY COLUMN `LabWorkRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectIDComp` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `TypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDVolume` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDUnitPrice` int DEFAULT NULL,
  ADD INDEX `labworkrequestdetails_BarangID` (`BarangID`),
  ADD INDEX `labworkrequestdetails_LabWorkRequestID` (`LabWorkRequestID`),
  ADD INDEX `labworkrequestdetails_PrincipalID` (`PrincipalID`),
  ADD INDEX `labworkrequestdetails_ProjectID` (`ProjectID`),
  ADD INDEX `labworkrequestdetails_ProjectIDComp` (`ProjectIDComp`),
  ADD INDEX `labworkrequestdetails_SatuanIDUnitPrice` (`SatuanIDUnitPrice`),
  ADD INDEX `labworkrequestdetails_SatuanIDVolume` (`SatuanIDVolume`),
  ADD INDEX `labworkrequestdetails_TypeID` (`TypeID`),
  ADD INDEX `LabWorkRequestDetailStatusID` (`LabWorkRequestDetailStatusID`,`LabWorkRequestID`,`ProductCategory`,`PrincipalID`,`BarangID`,`TypeID`,`SatuanIDVolume`,`SatuanIDUnitPrice`);
ALTER TABLE `labworkrequestdetailsassignment`
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestDetailID` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `labworkrequestdetailsassignment_LabWorkRequestDetailID` (`LabWorkRequestDetailID`),
  ADD INDEX `labworkrequestdetailsassignment_LabWorkRequestDetailStatusID` (`LabWorkRequestDetailStatusID`),
  ADD INDEX `labworkrequestdetailsassignment_UserID` (`UserID`),
  ADD INDEX `LabWorkRequestID` (`LabWorkRequestID`,`LabWorkRequestDetailID`,`LabWorkRequestDetailStatusID`,`UserID`);
ALTER TABLE `labworkrequestlink`
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  ADD INDEX `labworkrequestlink_LabWorkRequestID` (`LabWorkRequestID`);
ALTER TABLE `lembur`
  MODIFY COLUMN `LemburTypeID` int DEFAULT NULL,
  MODIFY COLUMN `LemburStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  ADD INDEX `lembur_LemburStatusID` (`LemburStatusID`),
  ADD INDEX `lembur_UserIDInput` (`UserIDInput`),
  ADD INDEX `lembur_UserIDSales` (`UserIDSales`),
  ADD INDEX `LemburTypeID` (`LemburTypeID`,`LemburStatusID`,`UserIDInput`,`UserIDSales`);
ALTER TABLE `lemburassignment`
  MODIFY COLUMN `LemburID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `LemburStatusID` int DEFAULT NULL,
  ADD INDEX `lemburassignment_LemburStatusID` (`LemburStatusID`),
  ADD INDEX `lemburassignment_UserID` (`UserID`),
  ADD INDEX `LemburID` (`LemburID`,`UserID`,`LemburStatusID`);
ALTER TABLE `news`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `news_UserID` (`UserID`);
ALTER TABLE `onleave`
  MODIFY COLUMN `OnLeaveStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `UserPengganti1` int DEFAULT NULL,
  MODIFY COLUMN `UserPengganti2` int DEFAULT NULL,
  MODIFY COLUMN `OnLeaveLimitID` int DEFAULT NULL,
  ADD INDEX `onleave_OnLeaveLimitID` (`OnLeaveLimitID`),
  ADD INDEX `onleave_UserIDInput` (`UserIDInput`),
  ADD INDEX `onleave_UserIDSales` (`UserIDSales`),
  ADD INDEX `onleave_UserPengganti1` (`UserPengganti1`),
  ADD INDEX `onleave_UserPengganti2` (`UserPengganti2`),
  ADD INDEX `OnLeaveStatusID` (`OnLeaveStatusID`,`UserIDInput`,`UserIDSales`,`UserPengganti1`,`UserPengganti2`,`OnLeaveLimitID`);
ALTER TABLE `onleaveadditional`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `OnLeaveLimitID` int DEFAULT NULL,
  ADD INDEX `onleaveadditional_OnLeaveLimitID` (`OnLeaveLimitID`),
  ADD INDEX `onleaveadditional_UserID` (`UserID`),
  ADD INDEX `UserIDInput` (`UserIDInput`,`UserID`,`OnLeaveLimitID`);
ALTER TABLE `onleaveadditionalassignment`
  MODIFY COLUMN `OnLeaveAdditionalID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `onleaveadditionalassignment_UserID` (`UserID`),
  ADD INDEX `OnLeaveAdditionalID` (`OnLeaveAdditionalID`,`UserID`);
ALTER TABLE `onleaveassignment`
  MODIFY COLUMN `OnLeaveID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `OnLeaveStatusID` int DEFAULT NULL,
  ADD INDEX `onleaveassignment_OnLeaveStatusID` (`OnLeaveStatusID`),
  ADD INDEX `onleaveassignment_UserID` (`UserID`),
  ADD INDEX `OnLeaveID` (`OnLeaveID`,`UserID`,`OnLeaveStatusID`);
ALTER TABLE `packing`
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `SatuanID` (`SatuanID`);
ALTER TABLE `potentialsales`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`,`PrincipalID`,`BarangID`),
  ADD INDEX `potentialsales_BarangID` (`BarangID`),
  ADD INDEX `potentialsales_PrincipalID` (`PrincipalID`);
ALTER TABLE `potentialsaleshistory`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `PotentialSalesID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`,`PotentialSalesID`,`UserID`,`PrincipalID`,`BarangID`),
  ADD INDEX `potentialsaleshistory_BarangID` (`BarangID`),
  ADD INDEX `potentialsaleshistory_PotentialSalesID` (`PotentialSalesID`),
  ADD INDEX `potentialsaleshistory_PrincipalID` (`PrincipalID`),
  ADD INDEX `potentialsaleshistory_UserID` (`UserID`);
ALTER TABLE `principalcp`
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL,
  ADD INDEX `principalcp_AddressType` (`AddressType`),
  ADD INDEX `principalcp_PrincipalID` (`PrincipalID`);
ALTER TABLE `principalcpassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalCPID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL,
  ADD INDEX `principalcpassignment_AddressType` (`AddressType`),
  ADD INDEX `principalcpassignment_PrincipalCPID` (`PrincipalCPID`),
  ADD INDEX `principalcpassignment_PrincipalID` (`PrincipalID`),
  ADD INDEX `principalcpassignment_UsersID` (`UsersID`);
ALTER TABLE `principalfaq`
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  ADD INDEX `principalfaq_PrincipalID` (`PrincipalID`);
ALTER TABLE `principalfaqhistory`
  MODIFY COLUMN `PrincipalFAQID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  ADD INDEX `principalfaqhistory_PrincipalFAQID` (`PrincipalFAQID`),
  ADD INDEX `principalfaqhistory_PrincipalID` (`PrincipalID`);
ALTER TABLE `printeditemfulfillment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  ADD INDEX `printeditemfulfillment_UserIDInput` (`UserIDInput`);
ALTER TABLE `product`
  MODIFY COLUMN `ClassID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `PackingID` int DEFAULT NULL,
  ADD INDEX `ClassID` (`ClassID`,`PrincipalID`,`PackingID`),
  ADD INDEX `product_PackingID` (`PackingID`),
  ADD INDEX `product_PrincipalID` (`PrincipalID`);
ALTER TABLE `productapplication`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  ADD INDEX `productapplication_ApplicationID` (`ApplicationID`),
  ADD INDEX `productapplication_ProductID` (`ProductID`),
  ADD INDEX `UserIDInput` (`UserIDInput`,`ProductID`,`ApplicationID`);
ALTER TABLE `productcategory`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `CategoryID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  ADD INDEX `productcategory_CategoryID` (`CategoryID`),
  ADD INDEX `productcategory_ProductID` (`ProductID`),
  ADD INDEX `UserIDInput` (`UserIDInput`,`CategoryID`,`ProductID`);
ALTER TABLE `proposedcreditceiling`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermID` int DEFAULT NULL,
  MODIFY COLUMN `CCStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `JustificationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermApprovedID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`,`CCStatusID`,`UserIDInput`,`JustificationID`,`QuotationPaymentTermApprovedID`),
  ADD INDEX `proposedcreditceiling_CCStatusID` (`CCStatusID`),
  ADD INDEX `proposedcreditceiling_JustificationID` (`JustificationID`),
  ADD INDEX `proposedcreditceiling_QuotationPaymentTermApprovedID` (`QuotationPaymentTermApprovedID`),
  ADD INDEX `proposedcreditceiling_UserIDInput` (`UserIDInput`),
  ADD INDEX `QuotationPaymentTermID` (`QuotationPaymentTermID`);
ALTER TABLE `proposedcreditceilinghistory`
  MODIFY COLUMN `ProposedCCID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermID` int DEFAULT NULL,
  MODIFY COLUMN `CCStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `JustificationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermApprovedID` int DEFAULT NULL,
  ADD INDEX `ProposedCCID` (`ProposedCCID`,`CompanyID`,`QuotationPaymentTermID`,`CCStatusID`,`UserID`,`JustificationID`,`QuotationPaymentTermApprovedID`),
  ADD INDEX `proposedcreditceilinghistory_CCStatusID` (`CCStatusID`),
  ADD INDEX `proposedcreditceilinghistory_CompanyID` (`CompanyID`),
  ADD INDEX `proposedcreditceilinghistory_JustificationID` (`JustificationID`),
  ADD INDEX `proposedcreditceilinghistory_QuotationPaymentTermApprovedID` (`QuotationPaymentTermApprovedID`),
  ADD INDEX `proposedcreditceilinghistory_QuotationPaymentTermID` (`QuotationPaymentTermID`),
  ADD INDEX `proposedcreditceilinghistory_UserID` (`UserID`);
ALTER TABLE `purchaseorderdetails`
  MODIFY COLUMN `PurchaseOrderID` int DEFAULT NULL,
  MODIFY COLUMN `PurchaseOrderDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `PackingID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanOrderQtyID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  ADD INDEX `purchaseorderdetails_PackingID` (`PackingID`),
  ADD INDEX `purchaseorderdetails_PurchaseOrderDetailStatusID` (`PurchaseOrderDetailStatusID`),
  ADD INDEX `purchaseorderdetails_PurchaseOrderID` (`PurchaseOrderID`),
  ADD INDEX `purchaseorderdetails_SatuanID` (`SatuanID`),
  ADD INDEX `purchaseorderdetails_SatuanOrderQtyID` (`SatuanOrderQtyID`);
ALTER TABLE `purchaseorderdetailsassignment`
  MODIFY COLUMN `PurchaseOrderID` int DEFAULT NULL,
  MODIFY COLUMN `PurchaseOrderDetailID` int DEFAULT NULL,
  MODIFY COLUMN `PurchaseOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `purchaseorderdetailsassignment_PurchaseOrderDetailID` (`PurchaseOrderDetailID`),
  ADD INDEX `purchaseorderdetailsassignment_PurchaseOrderID` (`PurchaseOrderID`),
  ADD INDEX `purchaseorderdetailsassignment_PurchaseOrderStatusID` (`PurchaseOrderStatusID`),
  ADD INDEX `purchaseorderdetailsassignment_UserID` (`UserID`);
ALTER TABLE `quotationassignment`
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `qta_fk_QuotationID` (`QuotationID`),
  ADD INDEX `qta_fk_QuotationStatusID` (`QuotationStatusID`),
  ADD INDEX `qta_fk_UserID` (`UserID`);
ALTER TABLE `quotationdetailsassignment`
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDetailID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `qda_fk_QuotationDetailID` (`QuotationDetailID`),
  ADD INDEX `qda_fk_QuotationDetailStatusID` (`QuotationDetailStatusID`),
  ADD INDEX `qda_fk_QuotationID` (`QuotationID`),
  ADD INDEX `qda_fk_UserID` (`UserID`);
ALTER TABLE `quotationlink`
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  ADD INDEX `ql_fk_QuotationID` (`QuotationID`);
ALTER TABLE `reference`
  MODIFY COLUMN `PaymentTerm` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`),
  ADD INDEX `reference_PaymentTerm` (`PaymentTerm`);
ALTER TABLE `referencehistory`
  MODIFY COLUMN `ReferenceID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `PaymentTerm` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  ADD INDEX `referencehistory_CompanyID` (`CompanyID`),
  ADD INDEX `referencehistory_PaymentTerm` (`PaymentTerm`),
  ADD INDEX `referencehistory_UserID` (`UserID`),
  ADD INDEX `ReferenceID` (`ReferenceID`,`UserID`,`CompanyID`);
ALTER TABLE `relabelhistory`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  ADD INDEX `relabelhistory_UserIDInput` (`UserIDInput`);
ALTER TABLE `rolegadget`
  MODIFY COLUMN `RoleID` int DEFAULT NULL,
  MODIFY COLUMN `GadgetID` int DEFAULT NULL,
  ADD INDEX `rolegadget_GadgetID` (`GadgetID`),
  ADD INDEX `RoleID` (`RoleID`,`GadgetID`);
ALTER TABLE `rolemenu`
  MODIFY COLUMN `RoleID` int DEFAULT NULL,
  MODIFY COLUMN `MenuID` int DEFAULT NULL,
  ADD INDEX `RoleID` (`RoleID`,`MenuID`),
  ADD INDEX `rolemenu_MenuID` (`MenuID`);
ALTER TABLE `salesrebate`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateStatusID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CCPaymentTerm` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceRebateID` int DEFAULT NULL,
  ADD INDEX `salesrebate_CCPaymentTerm` (`CCPaymentTerm`),
  ADD INDEX `salesrebate_CompanyID` (`CompanyID`),
  ADD INDEX `salesrebate_DivisionID` (`DivisionID`),
  ADD INDEX `salesrebate_IndustryID` (`IndustryID`),
  ADD INDEX `salesrebate_ReferenceRebateID` (`ReferenceRebateID`),
  ADD INDEX `salesrebate_SalesRebateStatusID` (`SalesRebateStatusID`),
  ADD INDEX `salesrebate_UserIDInput` (`UserIDInput`),
  ADD INDEX `salesrebate_UserIDSales` (`UserIDSales`);
ALTER TABLE `salesrebateassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateStatusID` int DEFAULT NULL,
  ADD INDEX `salesrebateassignment_SalesRebateID` (`SalesRebateID`),
  ADD INDEX `salesrebateassignment_SalesRebateStatusID` (`SalesRebateStatusID`),
  ADD INDEX `salesrebateassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `salesrebateinvoice`
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserInput` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  ADD INDEX `salesrebateinvoice_CompanyID` (`CompanyID`),
  ADD INDEX `salesrebateinvoice_DivisionID` (`DivisionID`),
  ADD INDEX `salesrebateinvoice_IndustryID` (`IndustryID`),
  ADD INDEX `salesrebateinvoice_SalesRebateID` (`SalesRebateID`),
  ADD INDEX `salesrebateinvoice_SalesRebateInvoiceStatusID` (`SalesRebateInvoiceStatusID`),
  ADD INDEX `salesrebateinvoice_UserInput` (`UserInput`);
ALTER TABLE `salesrebateinvoiceassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceStatusID` int DEFAULT NULL,
  ADD INDEX `salesrebateinvoiceassignment_SalesRebateInvoiceID` (`SalesRebateInvoiceID`),
  ADD INDEX `salesrebateinvoiceassignment_SalesRebateInvoiceStatusID` (`SalesRebateInvoiceStatusID`),
  ADD INDEX `salesrebateinvoiceassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `salesrebateinvoicedetail`
  MODIFY COLUMN `SalesRebateInvoiceDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `PaymentCPID` int DEFAULT NULL,
  ADD INDEX `salesrebateinvoicedetail_PaymentCPID` (`PaymentCPID`),
  ADD INDEX `salesrebateinvoicedetail_SalesRebateID` (`SalesRebateID`),
  ADD INDEX `salesrebateinvoicedetail_SalesRebateInvoiceDetailStatusID` (`SalesRebateInvoiceDetailStatusID`),
  ADD INDEX `salesrebateinvoicedetail_SalesRebateInvoiceID` (`SalesRebateInvoiceID`);
ALTER TABLE `salesrebateinvoicepaymentdetail`
  MODIFY COLUMN `SalesRebateInvoiceDetailID` int DEFAULT NULL,
  ADD INDEX `salesrebateinvoicepaymentdetail_SalesRebateInvoiceDetailID` (`SalesRebateInvoiceDetailID`);
ALTER TABLE `sampleorder`
  MODIFY COLUMN `SampleOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceSOID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `LocationID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `PriorityID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderFeedbackStatusID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderByID` int DEFAULT NULL,
  ADD INDEX `sampleorder_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `sampleorder_CompanyID` (`CompanyID`),
  ADD INDEX `sampleorder_DeliveryID` (`DeliveryID`),
  ADD INDEX `sampleorder_DivisionID` (`DivisionID`),
  ADD INDEX `sampleorder_IndustryID` (`IndustryID`),
  ADD INDEX `sampleorder_LocationID` (`LocationID`),
  ADD INDEX `sampleorder_PriorityID` (`PriorityID`),
  ADD INDEX `sampleorder_ProjectID` (`ProjectID`),
  ADD INDEX `sampleorder_ReferenceSOID` (`ReferenceSOID`),
  ADD INDEX `sampleorder_SampleOrderByID` (`SampleOrderByID`),
  ADD INDEX `sampleorder_SampleOrderFeedbackStatusID` (`SampleOrderFeedbackStatusID`),
  ADD INDEX `sampleorder_UserIDInput` (`UserIDInput`),
  ADD INDEX `sampleorder_UserIDSales` (`UserIDSales`),
  ADD INDEX `SampleOrderStatusID` (`SampleOrderStatusID`,`ReferenceSOID`,`DeliveryID`,`CompanyID`,`CompanyCPID`,`LocationID`,`DivisionID`,`PriorityID`,`SampleOrderFeedbackStatusID`,`SampleOrderByID`);
ALTER TABLE `sampleorderassignment`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `sampleorderassignment_SampleOrderStatusID` (`SampleOrderStatusID`),
  ADD INDEX `sampleorderassignment_UserID` (`UserID`),
  ADD INDEX `SampleOrderID` (`SampleOrderID`,`SampleOrderStatusID`,`UserID`);
ALTER TABLE `sampleorderdetailassignment`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `sampleorderdetailassignment_SampleOrderDetailID` (`SampleOrderDetailID`),
  ADD INDEX `sampleorderdetailassignment_SampleOrderDetailStatusID` (`SampleOrderDetailStatusID`),
  ADD INDEX `sampleorderdetailassignment_UserID` (`UserID`),
  ADD INDEX `SampleOrderID` (`SampleOrderID`,`SampleOrderDetailID`,`SampleOrderDetailStatusID`,`UserID`);
ALTER TABLE `sampleorderlink`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  ADD INDEX `sampleorderlink_SampleOrderID` (`SampleOrderID`);
ALTER TABLE `samplerequestimport`
  MODIFY COLUMN `SampleRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceSRID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryID` int DEFAULT NULL,
  MODIFY COLUMN `UrgencyID` int DEFAULT NULL,
  MODIFY COLUMN `RequestFromID` int DEFAULT NULL,
  ADD INDEX `samplerequestimport_DeliveryID` (`DeliveryID`),
  ADD INDEX `samplerequestimport_PrincipalID` (`PrincipalID`),
  ADD INDEX `samplerequestimport_ReferenceSRID` (`ReferenceSRID`),
  ADD INDEX `samplerequestimport_RequestFromID` (`RequestFromID`),
  ADD INDEX `samplerequestimport_UrgencyID` (`UrgencyID`),
  ADD INDEX `samplerequestimport_UserIDInput` (`UserIDInput`),
  ADD INDEX `SampleRequestStatusID` (`SampleRequestStatusID`,`ReferenceSRID`,`UserIDInput`,`PrincipalID`,`DeliveryID`,`UrgencyID`,`RequestFromID`);
ALTER TABLE `samplerequestimportassignment`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `samplerequestimportassignment_SampleRequestStatusID` (`SampleRequestStatusID`),
  ADD INDEX `samplerequestimportassignment_UserID` (`UserID`),
  ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestStatusID`,`UserID`);
ALTER TABLE `samplerequestimportdetail`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `ReqCompanyID` int DEFAULT NULL,
  MODIFY COLUMN `GoodReceiptDetailID` int DEFAULT NULL,
  MODIFY COLUMN `BaranglistID` int DEFAULT NULL,
  ADD INDEX `samplerequestimportdetail_BarangID` (`BarangID`),
  ADD INDEX `samplerequestimportdetail_BaranglistID` (`BaranglistID`),
  ADD INDEX `samplerequestimportdetail_GoodReceiptDetailID` (`GoodReceiptDetailID`),
  ADD INDEX `samplerequestimportdetail_ReqCompanyID` (`ReqCompanyID`),
  ADD INDEX `samplerequestimportdetail_SampleRequestDetailStatusID` (`SampleRequestDetailStatusID`),
  ADD INDEX `samplerequestimportdetail_SatuanID` (`SatuanID`),
  ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestDetailStatusID`,`BarangID`,`SatuanID`,`ReqCompanyID`,`GoodReceiptDetailID`,`BaranglistID`);
ALTER TABLE `samplerequestimportdetailassignment`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestDetailID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `samplerequestimportdetailassignment_SampleRequestDetailID` (`SampleRequestDetailID`),
  ADD INDEX `samplerequestimportdetailassignment_SampleRequestDetailStatusID` (`SampleRequestDetailStatusID`),
  ADD INDEX `samplerequestimportdetailassignment_UserID` (`UserID`),
  ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestDetailID`,`SampleRequestDetailStatusID`,`UserID`);
ALTER TABLE `specialreference`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  ADD INDEX `CompanyID` (`CompanyID`);
ALTER TABLE `specialreferencehistory`
  MODIFY COLUMN `SpecialReferenceID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  ADD INDEX `specialreferencehistory_CompanyID` (`CompanyID`),
  ADD INDEX `specialreferencehistory_UserID` (`UserID`),
  ADD INDEX `SpecialReferenceID` (`SpecialReferenceID`,`UserID`,`CompanyID`);
ALTER TABLE `stockopname`
  MODIFY COLUMN `StockOpnameBy` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `WarehouseID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL,
  MODIFY COLUMN `UOMID` int DEFAULT NULL,
  ADD INDEX `stockopname_PackagingID` (`PackagingID`),
  ADD INDEX `stockopname_PrincipalID` (`PrincipalID`),
  ADD INDEX `stockopname_ProductID` (`ProductID`),
  ADD INDEX `stockopname_StockOpnameBy` (`StockOpnameBy`),
  ADD INDEX `stockopname_UOMID` (`UOMID`),
  ADD INDEX `stockopname_WarehouseID` (`WarehouseID`);
ALTER TABLE `stockopname_product`
  MODIFY COLUMN `UOMID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  ADD INDEX `stockopname_product_PrincipalID` (`PrincipalID`);
ALTER TABLE `stockopnamehistory`
  MODIFY COLUMN `StockOpnameID` int DEFAULT NULL,
  MODIFY COLUMN `StockOpnameStatusID` int DEFAULT NULL,
  MODIFY COLUMN `StockOpnameBy` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `WarehouseID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL,
  MODIFY COLUMN `UOMID` int DEFAULT NULL,
  ADD INDEX `stockopnamehistory_PackagingID` (`PackagingID`),
  ADD INDEX `stockopnamehistory_PrincipalID` (`PrincipalID`),
  ADD INDEX `stockopnamehistory_ProductID` (`ProductID`),
  ADD INDEX `stockopnamehistory_StockOpnameBy` (`StockOpnameBy`),
  ADD INDEX `stockopnamehistory_StockOpnameID` (`StockOpnameID`),
  ADD INDEX `stockopnamehistory_StockOpnameStatusID` (`StockOpnameStatusID`),
  ADD INDEX `stockopnamehistory_UOMID` (`UOMID`),
  ADD INDEX `stockopnamehistory_WarehouseID` (`WarehouseID`);
ALTER TABLE `successstory`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  ADD INDEX `successstory_ApplicationID` (`ApplicationID`),
  ADD INDEX `successstory_BarangID` (`BarangID`),
  ADD INDEX `successstory_DivisionID` (`DivisionID`),
  ADD INDEX `successstory_GroupDivisionID` (`GroupDivisionID`),
  ADD INDEX `successstory_PrincipalID` (`PrincipalID`),
  ADD INDEX `successstory_UserIDSales` (`UserIDSales`),
  ADD INDEX `UserIDInput` (`UserIDInput`,`UserIDSales`,`GroupDivisionID`,`DivisionID`,`ApplicationID`,`PrincipalID`,`BarangID`);
ALTER TABLE `successstoryassignment`
  MODIFY COLUMN `SuccessStoryID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `successstoryassignment_UserID` (`UserID`),
  ADD INDEX `SuccessStoryID` (`SuccessStoryID`,`Tanggal`,`UserID`);
ALTER TABLE `suratjalandetails`
  MODIFY COLUMN `SuratJalanID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListID` int DEFAULT NULL,
  ADD INDEX `suratjalandetails_ApplicationID` (`ApplicationID`),
  ADD INDEX `suratjalandetails_BarangID` (`BarangID`),
  ADD INDEX `suratjalandetails_BarangListID` (`BarangListID`),
  ADD INDEX `suratjalandetails_SampleOrderID` (`SampleOrderID`),
  ADD INDEX `suratjalandetails_SatuanID` (`SatuanID`),
  ADD INDEX `SuratJalanID` (`SuratJalanID`,`SampleOrderID`,`BarangID`,`SatuanID`,`ApplicationID`,`BarangListID`);
ALTER TABLE `userbusinesstravelbranch`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  ADD INDEX `userbusinesstravelbranch_BranchID` (`BranchID`),
  ADD INDEX `userbusinesstravelbranch_UserID` (`UserID`);
ALTER TABLE `userdetails`
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  ADD INDEX `BranchID` (`BranchID`,`DepartmentID`,`DivisionID`,`MaritalStatus`),
  ADD INDEX `userdetails_DepartmentID` (`DepartmentID`),
  ADD INDEX `userdetails_DivisionID` (`DivisionID`);
ALTER TABLE `userdivision`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  ADD INDEX `userdivision_DivisionID` (`DivisionID`),
  ADD INDEX `UserID` (`UserID`,`DivisionID`);
ALTER TABLE `usereducation`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `EducationID` int DEFAULT NULL,
  ADD INDEX `usereducation_EducationID` (`EducationID`),
  ADD INDEX `UserID` (`UserID`,`EducationID`);
ALTER TABLE `userjob`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `UserID` (`UserID`);
ALTER TABLE `userlabgroupdivision`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL,
  ADD INDEX `userlabgroupdivision_GroupDivisionID` (`GroupDivisionID`),
  ADD INDEX `userlabgroupdivision_UserID` (`UserID`);
ALTER TABLE `userprincipal`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  ADD INDEX `UserID` (`UserID`,`PrincipalID`),
  ADD INDEX `userprincipal_PrincipalID` (`PrincipalID`);
ALTER TABLE `usersperiode`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `usersperiode_UserID` (`UserID`);
ALTER TABLE `userwarehouse`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `WarehouseID` int DEFAULT NULL,
  ADD INDEX `userwarehouse_WarehouseID` (`WarehouseID`);
ALTER TABLE `vehicle`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwner` int DEFAULT NULL,
  MODIFY COLUMN `VehicleTypeID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandTypeID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleColorID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleFuelTypeID` int DEFAULT NULL,
  ADD INDEX `UserIDInput` (`UserIDInput`,`UserIDOwner`,`VehicleTypeID`,`VehicleBrandID`,`VehicleBrandTypeID`,`VehicleColorID`,`VehicleFuelTypeID`,`GasolineID`),
  ADD INDEX `vehicle_UserIDOwner` (`UserIDOwner`),
  ADD INDEX `vehicle_VehicleBrandID` (`VehicleBrandID`),
  ADD INDEX `vehicle_VehicleBrandTypeID` (`VehicleBrandTypeID`),
  ADD INDEX `vehicle_VehicleColorID` (`VehicleColorID`),
  ADD INDEX `vehicle_VehicleFuelTypeID` (`VehicleFuelTypeID`),
  ADD INDEX `vehicle_VehicleTypeID` (`VehicleTypeID`);
ALTER TABLE `vehicleassignment`
  MODIFY COLUMN `VehicleID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwnerBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleTypeIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandTypeIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleColorIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleFuelTypeIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwnerAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleTypeIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandTypeIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleColorIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleFuelTypeIDAfter` int DEFAULT NULL,
  ADD INDEX `vehicleassignment_UserIDInput` (`UserIDInput`),
  ADD INDEX `vehicleassignment_UserIDOwnerAfter` (`UserIDOwnerAfter`),
  ADD INDEX `vehicleassignment_UserIDOwnerBefore` (`UserIDOwnerBefore`),
  ADD INDEX `vehicleassignment_VehicleBrandIDAfter` (`VehicleBrandIDAfter`),
  ADD INDEX `vehicleassignment_VehicleBrandIDBefore` (`VehicleBrandIDBefore`),
  ADD INDEX `vehicleassignment_VehicleBrandTypeIDAfter` (`VehicleBrandTypeIDAfter`),
  ADD INDEX `vehicleassignment_VehicleBrandTypeIDBefore` (`VehicleBrandTypeIDBefore`),
  ADD INDEX `vehicleassignment_VehicleColorIDAfter` (`VehicleColorIDAfter`),
  ADD INDEX `vehicleassignment_VehicleColroIDBefore` (`VehicleColorIDBefore`),
  ADD INDEX `vehicleassignment_VehicleFuelTypeIDAfter` (`VehicleFuelTypeIDAfter`),
  ADD INDEX `vehicleassignment_VehicleFuelTypeIDBefore` (`VehicleFuelTypeIDBefore`),
  ADD INDEX `vehicleassignment_VehicleID` (`VehicleID`),
  ADD INDEX `vehicleassignment_VehicleStatusID` (`VehicleStatusID`),
  ADD INDEX `vehicleassignment_VehicleTypeIDAfter` (`VehicleTypeIDAfter`),
  ADD INDEX `vehicleassignment_VehicleTypeIDBefore` (`VehicleTypeIDBefore`);
ALTER TABLE `vehiclebrandtype`
  MODIFY COLUMN `VehicleBrandID` int DEFAULT NULL,
  ADD INDEX `VehicleBrandID` (`VehicleBrandID`);
ALTER TABLE `vehicleservicerequest`
  MODIFY COLUMN `VehicleServiceRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `VehicleID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwner` int DEFAULT NULL,
  ADD INDEX `vehicleservicerequest_UserIDInput` (`UserIDInput`),
  ADD INDEX `vehicleservicerequest_UserIDOwner` (`UserIDOwner`),
  ADD INDEX `vehicleservicerequest_VehicleID` (`VehicleID`),
  ADD INDEX `VehicleServiceRequestStatusID` (`VehicleServiceRequestStatusID`,`UserIDInput`,`VehicleID`,`UserIDOwner`);
ALTER TABLE `vehicleservicerequestassignment`
  MODIFY COLUMN `VehicleServiceRequestID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `vehicleservicerequestassignment_UserID` (`UserID`),
  ADD INDEX `vehicleservicerequestassignment_VehicleServiceRequestStatusID` (`VehicleServiceRequestStatusID`),
  ADD INDEX `VehicleServiceRequestID` (`VehicleServiceRequestID`,`VehicleServiceRequestStatusID`,`UserID`);
ALTER TABLE `vehicleservicerequestdetails`
  MODIFY COLUMN `VehicleServiceRequestID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceTypeID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestDetailStatus` int DEFAULT NULL,
  ADD INDEX `vehicleservicerequestdetails_VehicleServiceRequestDetailStatus` (`VehicleServiceRequestDetailStatus`),
  ADD INDEX `vehicleservicerequestdetails_VehicleServiceTypeID` (`VehicleServiceTypeID`),
  ADD INDEX `VehicleServiceRequestID` (`VehicleServiceRequestID`,`VehicleServiceTypeID`,`VehicleServiceRequestDetailStatus`);
ALTER TABLE `vehicleservicerequestdetailsassigntment`
  MODIFY COLUMN `VehicleServiceRequestID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestDetailID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  ADD INDEX `vehicleservicerequestdetailsassigntment_UserID` (`UserID`),
  ADD INDEX `vehicleservicerequestdetailsassigntment_VehSerReqDetailID` (`VehicleServiceRequestDetailID`),
  ADD INDEX `vehicleservicerequestdetailsassigntment_VehSerReqStatusID` (`VehicleServiceRequestStatusID`),
  ADD INDEX `VehicleServiceRequestID` (`VehicleServiceRequestID`,`VehicleServiceRequestDetailID`,`VehicleServiceRequestStatusID`,`UserID`);
ALTER TABLE `visitplan`
  DROP INDEX `VisitPlanStatusID`;
ALTER TABLE `visitplan`
  MODIFY COLUMN `VisitPlanStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDVisitWith` int DEFAULT NULL,
  MODIFY COLUMN `VisitingPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPrincipalCPID` int DEFAULT NULL,
  ADD INDEX `DivisionID` (`DivisionID`),
  ADD INDEX `UserIDInput` (`UserIDInput`,`UserIDSales`,`CompanyID`,`CompanyCPID`,`UserIDVisitWith`),
  ADD INDEX `visitplan_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `visitplan_CompanyID` (`CompanyID`),
  ADD INDEX `visitplan_ProjectID` (`ProjectID`),
  ADD INDEX `visitplan_UserIDSales` (`UserIDSales`),
  ADD INDEX `visitplan_UserIDVisitWith` (`UserIDVisitWith`),
  ADD INDEX `visitplan_VisitingPrincipalID` (`VisitingPrincipalID`),
  ADD INDEX `visitplan_VisitPrincipalCPID` (`VisitPrincipalCPID`),
  ADD INDEX `VisitPlanStatusID_3` (`VisitPlanStatusID`,`DivisionID`,`UserIDInput`,`UserIDSales`,`CompanyID`,`CompanyCPID`,`UserIDVisitWith`),
  ADD INDEX `VisitPlanStatusID` (`VisitPlanStatusID`);
ALTER TABLE `visitplanassignment`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPlanStatusID` int DEFAULT NULL,
  ADD INDEX `visitplanassignment_UserID` (`UserID`),
  ADD INDEX `visitplanassignment_VisitPlanStatusID` (`VisitPlanStatusID`);
ALTER TABLE `visitplancompanycpdetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  ADD INDEX `visitplancompanycpdetail_CompanyCPID` (`CompanyCPID`),
  ADD INDEX `visitplancompanycpdetail_VisitPlanID` (`VisitPlanID`);
ALTER TABLE `visitplandetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `ActionID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `VisitActionStatusID` int DEFAULT NULL,
  ADD INDEX `visitplandetail_ActionID` (`ActionID`),
  ADD INDEX `visitplandetail_BarangID` (`BarangID`),
  ADD INDEX `visitplandetail_PrincipalID` (`PrincipalID`),
  ADD INDEX `visitplandetail_ProjectID` (`ProjectID`);
ALTER TABLE `visitplandetailassignment`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPlanDetailID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPlanStatusID` int DEFAULT NULL,
  MODIFY COLUMN `VisitActionStatusID` int DEFAULT NULL,
  ADD INDEX `visitplandetailassignment_UserID` (`UserID`),
  ADD INDEX `visitplandetailassignment_VisitPlanDetailID` (`VisitPlanDetailID`),
  ADD INDEX `visitplandetailassignment_VisitPlanStatusID` (`VisitPlanStatusID`);
ALTER TABLE `visitplanfrienddetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDVisitWith` int DEFAULT NULL,
  ADD INDEX `visitplanfrienddetail_UserIDVisitWith` (`UserIDVisitWith`),
  ADD INDEX `visitplanfrienddetail_VisitPlanID` (`VisitPlanID`);
ALTER TABLE `visitplanlink` MODIFY COLUMN `VisitPlanID` int DEFAULT NULL;
ALTER TABLE `visitplanprincipalvisitdetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `VisitingPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `VisitingPrincipalCPID` int DEFAULT NULL,
  ADD INDEX `visitplanprincipalvisitdetail_VisitingPrincipalCPID` (`VisitingPrincipalCPID`),
  ADD INDEX `visitplanprincipalvisitdetail_VisitingPrincipalID` (`VisitingPrincipalID`),
  ADD INDEX `visitplanprincipalvisitdetail_VisitPlanID` (`VisitPlanID`);
ALTER TABLE `warehouse`
  MODIFY COLUMN `ParentID` int DEFAULT NULL,
  ADD INDEX `warehouse_ParentID` (`ParentID`);
ALTER TABLE `purchaseorderassignment`
  ADD INDEX `purchaseorderassignment_PurchaseOrderID` (`PurchaseOrderID`),
  ADD INDEX `purchaseorderassignment_PurchaseOrderStatusID` (`PurchaseOrderStatusID`),
  ADD INDEX `purchaseorderassignment_UserID` (`UserID`);


-- ---------------------------------------------------------------------
-- SECTIONS 5 AND 6 RUN AS ONE TRANSACTION.
-- Both contain nothing but InnoDB UPDATEs -- 1,273 of them (1 in 4c + 636 in 5 + 636 in 6),
-- no DDL -- so no implicit commit can
-- split them. Without this, a lock wait, a deadlock against the legacy app, or an operator
-- Ctrl-C part way through leaves production with some foreign-key columns cleaned and the rest
-- not, no rollback, and nothing in the output saying where it stopped. The script is not
-- resumable, so that state is only recoverable from the backup.
-- ⚠ CORRECTED 2026-08-14. The previous revision set only `lock_wait_timeout` here and RESTORED
-- it immediately after the COMMIT, which applied the guard to the sections that do not need it
-- and removed it before the ones that do:
--   * `lock_wait_timeout` bounds METADATA-lock waits. Sections 4c/5/6 are 1,273 InnoDB UPDATEs,
--     whose contention with the live legacy app is ROW-lock contention -- governed by
--     `innodb_lock_wait_timeout` (default 50s), which was never set.
--   * Sections 7 and 8 are the 1,296 ALTERs that actually take metadata locks, and they ran
--     OUTSIDE the guard at MariaDB 10.4's default `lock_wait_timeout` of 86400 seconds. One
--     ALTER stuck behind a long-running app query would stall the whole run with no timeout,
--     and every query arriving afterwards queues behind that ALTER.
-- Both are now set here and both stay set until the end of the file.
-- ---------------------------------------------------------------------
SET SESSION lock_wait_timeout = 60;
SET SESSION innodb_lock_wait_timeout = 60;
START TRANSACTION;

-- ---------------------------------------------------------------------
-- SECTION 4c - ONE-OFF DATA REPAIR: quotationdetails.QuotationPackID
--
-- 863 rows hold a QuotationPackID that `quotationpack` does not define. Without this repair,
-- section 6 would null every one of them and the information would be gone for good.
--
-- WHAT THEY ACTUALLY ARE. The values run 24-122; `quotationpack` stops at 23. All 863 resolve
-- against `packing` (ids 1-131), NONE of the 863 has a PackingID of its own (it is 0 in every
-- case), and -- the part that settles it -- `QuantityPacking` matches the leading number of the
-- corresponding `packing`.`PackingName` row for row:
--
--     QuotationPackID  QuantityPacking   packing.PackingName
--                  46            30.00   30 kg/pail
--                  56            25.00   25 kg/pail
--                  83            10.00   10 kg/pail
--                  91            20.00   20 kg/pail
--                  37            25.00   25 kg/box
--                  62             1.00   1 unit
--
-- Random ids into a 131-row table do not correlate with a quantity column. A legacy screen wrote
-- the PACKING id into the QUOTATIONPACK column. Same shape as the colliding legacy conventions
-- documented for `<detail>.ProjectID` in .claude/rules/company-project-links.md.
--
-- WHAT THIS DOES. Moves the value to the column it belongs in and leaves the 0-sentinel behind,
-- which section 5 then turns into NULL. Net effect on the schema: both foreign keys apply
-- cleanly. Net effect on the app: an improvement. `QuotationController::reportPackName()` reads
--     if ((int) $r->QuotationPackID === 0) $name = $r->PackingName;
-- so today these rows print a bare quantity with no unit -- the pack name resolves through
-- neither table. After this they print "25 kg/box" again.
--
-- The FK direction is NOT changed: `QuotationPackID` -> `quotationpack` is correct and is what
-- `QuotationDetails::quotationPack()` and five controller joins use. The data was wrong, not the
-- key. 63 needs no equivalent repair -- it has zero orphans on this column.
--
-- GUARDED THREE WAYS, so it can only touch the rows described above: the value must fail to
-- resolve in `quotationpack`, must resolve in `packing`, and the row must have no PackingID
-- already. Re-running finds nothing. It is inside the transaction with sections 5 and 6, so a
-- later failure rolls it back with them.
-- ---------------------------------------------------------------------
UPDATE `quotationdetails` d
  JOIN `packing` p ON p.`ID` = d.`QuotationPackID`
  LEFT JOIN `quotationpack` qp ON qp.`ID` = d.`QuotationPackID`
SET d.`PackingID` = d.`QuotationPackID`,
    d.`QuotationPackID` = 0
WHERE d.`QuotationPackID` IS NOT NULL
  AND d.`QuotationPackID` <> 0
  AND qp.`ID` IS NULL
  AND (d.`PackingID` = 0 OR d.`PackingID` IS NULL);

-- ---------------------------------------------------------------------
-- SECTION B - Cleanup: 0-sentinels AND orphaned references, in one pass per table
--   = the original sections 5 and 6, merged. 1,272 UPDATEs -> 157.
--
-- The two sections targeted EXACTLY the same 636 columns. Per column the merged predicate is
--     `c` IS NOT NULL AND (`c` = 0 OR parent.ID IS NULL)
-- which is the union of "= 0" (section 5) and "orphan" (section 6), and agrees with them row
-- for row. A row already NULL is skipped, as before. Every LEFT JOIN is a primary-key
-- equality, so none of them can multiply rows.
--
-- Still inside the SAME transaction as section 4c, with the same lock timeouts. This is a
-- DATA change and is not reversible from this script -- run the audit first.
-- ---------------------------------------------------------------------
UPDATE `application` c
  LEFT JOIN `division` p0 ON c.`DivisionID` = p0.`ID`
  LEFT JOIN `groupdivision` p1 ON c.`GroupDivisionID` = p1.`ID`
   SET
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p0.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`GroupDivisionID` = IF((c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p1.`ID` IS NULL)), NULL, c.`GroupDivisionID`)
 WHERE  (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p0.`ID` IS NULL))
    OR (c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p1.`ID` IS NULL));
UPDATE `bank` c
  LEFT JOIN `quotationpricedesc` p0 ON c.`QuotationPriceDescID` = p0.`ID`
   SET
       c.`QuotationPriceDescID` = IF((c.`QuotationPriceDescID` IS NOT NULL AND (c.`QuotationPriceDescID` = 0 OR p0.`ID` IS NULL)), NULL, c.`QuotationPriceDescID`)
 WHERE  (c.`QuotationPriceDescID` IS NOT NULL AND (c.`QuotationPriceDescID` = 0 OR p0.`ID` IS NULL));
UPDATE `bankdivision` c
  LEFT JOIN `bank` p0 ON c.`BankID` = p0.`ID`
  LEFT JOIN `division` p1 ON c.`DivisionID` = p1.`ID`
   SET
       c.`BankID` = IF((c.`BankID` IS NOT NULL AND (c.`BankID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BankID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DivisionID`)
 WHERE  (c.`BankID` IS NOT NULL AND (c.`BankID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p1.`ID` IS NULL));
UPDATE `barang` c
  LEFT JOIN `category` p0 ON c.`CategoryID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `satuan` p2 ON c.`SatuanID` = p2.`ID`
  LEFT JOIN `type` p3 ON c.`TypeID` = p3.`ID`
   SET
       c.`CategoryID` = IF((c.`CategoryID` IS NOT NULL AND (c.`CategoryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CategoryID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p2.`ID` IS NULL)), NULL, c.`SatuanID`),
       c.`TypeID` = IF((c.`TypeID` IS NOT NULL AND (c.`TypeID` = 0 OR p3.`ID` IS NULL)), NULL, c.`TypeID`)
 WHERE  (c.`CategoryID` IS NOT NULL AND (c.`CategoryID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p2.`ID` IS NULL))
    OR (c.`TypeID` IS NOT NULL AND (c.`TypeID` = 0 OR p3.`ID` IS NULL));
UPDATE `baranglist` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `barangliststatus` p1 ON c.`BarangListStatusID` = p1.`ID`
  LEFT JOIN `sampleorderdetail` p2 ON c.`SampleOrderDetailID` = p2.`ID`
  LEFT JOIN `satuan` p3 ON c.`SatuanID` = p3.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`BarangListStatusID` = IF((c.`BarangListStatusID` IS NOT NULL AND (c.`BarangListStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangListStatusID`),
       c.`SampleOrderDetailID` = IF((c.`SampleOrderDetailID` IS NOT NULL AND (c.`SampleOrderDetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`SampleOrderDetailID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p3.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangListStatusID` IS NOT NULL AND (c.`BarangListStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`SampleOrderDetailID` IS NOT NULL AND (c.`SampleOrderDetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p3.`ID` IS NULL));
UPDATE `baranglists` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `satuan` p1 ON c.`SatuanID` = p1.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p1.`ID` IS NULL));
UPDATE `barangstockmin` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `satuan` p1 ON c.`SatuanID` = p1.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p1.`ID` IS NULL));
UPDATE `budgetandtarget` c
  LEFT JOIN `budgetandtargetperiode` p0 ON c.`BudgetAndTargetPeriodeID` = p0.`ID`
  LEFT JOIN `budgetandtargetstatus` p1 ON c.`BudgetAndTargetStatusID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
   SET
       c.`BudgetAndTargetPeriodeID` = IF((c.`BudgetAndTargetPeriodeID` IS NOT NULL AND (c.`BudgetAndTargetPeriodeID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BudgetAndTargetPeriodeID`),
       c.`BudgetAndTargetStatusID` = IF((c.`BudgetAndTargetStatusID` IS NOT NULL AND (c.`BudgetAndTargetStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BudgetAndTargetStatusID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`BudgetAndTargetPeriodeID` IS NOT NULL AND (c.`BudgetAndTargetPeriodeID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BudgetAndTargetStatusID` IS NOT NULL AND (c.`BudgetAndTargetStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p2.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p6.`ID` IS NULL));
UPDATE `budgetandtargetassignment` c
  LEFT JOIN `budgetandtarget` p0 ON c.`BudgetAndTargetID` = p0.`ID`
  LEFT JOIN `budgetandtargetstatus` p1 ON c.`BudgetAndTargetStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`BudgetAndTargetID` = IF((c.`BudgetAndTargetID` IS NOT NULL AND (c.`BudgetAndTargetID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BudgetAndTargetID`),
       c.`BudgetAndTargetStatusID` = IF((c.`BudgetAndTargetStatusID` IS NOT NULL AND (c.`BudgetAndTargetStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BudgetAndTargetStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`BudgetAndTargetID` IS NOT NULL AND (c.`BudgetAndTargetID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BudgetAndTargetStatusID` IS NOT NULL AND (c.`BudgetAndTargetStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `comissionpercentage` c
  LEFT JOIN `principal` p0 ON c.`PrincipalID` = p0.`ID`
   SET
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL));
UPDATE `company` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `companycategory` p1 ON c.`CompanyCategoryID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDSales` = p4.`ID`
   SET
       c.`BranchID` = IF((c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BranchID`),
       c.`CompanyCategoryID` = IF((c.`CompanyCategoryID` IS NOT NULL AND (c.`CompanyCategoryID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyCategoryID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyCategoryID` IS NOT NULL AND (c.`CompanyCategoryID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p4.`ID` IS NULL));
UPDATE `companyaccessothers` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `companycategory` c
  LEFT JOIN `groupdivision` p0 ON c.`GroupDivID` = p0.`ID`
   SET
       c.`GroupDivID` = IF((c.`GroupDivID` IS NOT NULL AND (c.`GroupDivID` = 0 OR p0.`ID` IS NULL)), NULL, c.`GroupDivID`)
 WHERE  (c.`GroupDivID` IS NOT NULL AND (c.`GroupDivID` = 0 OR p0.`ID` IS NULL));
UPDATE `companycategorylist` c
  LEFT JOIN `companycategory` p0 ON c.`CompanyCategoryID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
   SET
       c.`CompanyCategoryID` = IF((c.`CompanyCategoryID` IS NOT NULL AND (c.`CompanyCategoryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCategoryID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`)
 WHERE  (c.`CompanyCategoryID` IS NOT NULL AND (c.`CompanyCategoryID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL));
UPDATE `companycp` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
   SET
       c.`AddressType` = IF((c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL)), NULL, c.`AddressType`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`)
 WHERE  (c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL));
UPDATE `companycpassignment` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `companycp` p1 ON c.`CompanyCPID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UsersID` = p3.`ID`
   SET
       c.`AddressType` = IF((c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL)), NULL, c.`AddressType`),
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`UsersID` = IF((c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UsersID`)
 WHERE  (c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p3.`ID` IS NULL));
UPDATE `companyhistory` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDSales` = p4.`ID`
   SET
       c.`BranchID` = IF((c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BranchID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p4.`ID` IS NULL));
UPDATE `companyindustry` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `industry` p1 ON c.`IndustryID` = p1.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p1.`ID` IS NULL)), NULL, c.`IndustryID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p1.`ID` IS NULL));
UPDATE `companyproduct` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`CCBarangID` = p1.`ID`
  LEFT JOIN `satuan` p2 ON c.`CCPriceSatuanID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`CCPrincipalID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`CCVolumeSatuanID` = p4.`ID`
  LEFT JOIN `company` p5 ON c.`CompanyID` = p5.`ID`
  LEFT JOIN `barang` p6 ON c.`CompetitorBarangID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`CompetitorPriceSatuanID` = p7.`ID`
  LEFT JOIN `principal` p8 ON c.`CompetitorPrincipalID` = p8.`ID`
  LEFT JOIN `satuan` p9 ON c.`CompetitorVolumeSatuanID` = p9.`ID`
  LEFT JOIN `division` p10 ON c.`DivisionID` = p10.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CCBarangID` = IF((c.`CCBarangID` IS NOT NULL AND (c.`CCBarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CCBarangID`),
       c.`CCPriceSatuanID` = IF((c.`CCPriceSatuanID` IS NOT NULL AND (c.`CCPriceSatuanID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CCPriceSatuanID`),
       c.`CCPrincipalID` = IF((c.`CCPrincipalID` IS NOT NULL AND (c.`CCPrincipalID` = 0 OR p3.`ID` IS NULL)), NULL, c.`CCPrincipalID`),
       c.`CCVolumeSatuanID` = IF((c.`CCVolumeSatuanID` IS NOT NULL AND (c.`CCVolumeSatuanID` = 0 OR p4.`ID` IS NULL)), NULL, c.`CCVolumeSatuanID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p5.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`CompetitorBarangID` = IF((c.`CompetitorBarangID` IS NOT NULL AND (c.`CompetitorBarangID` = 0 OR p6.`ID` IS NULL)), NULL, c.`CompetitorBarangID`),
       c.`CompetitorPriceSatuanID` = IF((c.`CompetitorPriceSatuanID` IS NOT NULL AND (c.`CompetitorPriceSatuanID` = 0 OR p7.`ID` IS NULL)), NULL, c.`CompetitorPriceSatuanID`),
       c.`CompetitorPrincipalID` = IF((c.`CompetitorPrincipalID` IS NOT NULL AND (c.`CompetitorPrincipalID` = 0 OR p8.`ID` IS NULL)), NULL, c.`CompetitorPrincipalID`),
       c.`CompetitorVolumeSatuanID` = IF((c.`CompetitorVolumeSatuanID` IS NOT NULL AND (c.`CompetitorVolumeSatuanID` = 0 OR p9.`ID` IS NULL)), NULL, c.`CompetitorVolumeSatuanID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p10.`ID` IS NULL)), NULL, c.`DivisionID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CCBarangID` IS NOT NULL AND (c.`CCBarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CCPriceSatuanID` IS NOT NULL AND (c.`CCPriceSatuanID` = 0 OR p2.`ID` IS NULL))
    OR (c.`CCPrincipalID` IS NOT NULL AND (c.`CCPrincipalID` = 0 OR p3.`ID` IS NULL))
    OR (c.`CCVolumeSatuanID` IS NOT NULL AND (c.`CCVolumeSatuanID` = 0 OR p4.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p5.`ID` IS NULL))
    OR (c.`CompetitorBarangID` IS NOT NULL AND (c.`CompetitorBarangID` = 0 OR p6.`ID` IS NULL))
    OR (c.`CompetitorPriceSatuanID` IS NOT NULL AND (c.`CompetitorPriceSatuanID` = 0 OR p7.`ID` IS NULL))
    OR (c.`CompetitorPrincipalID` IS NOT NULL AND (c.`CompetitorPrincipalID` = 0 OR p8.`ID` IS NULL))
    OR (c.`CompetitorVolumeSatuanID` IS NOT NULL AND (c.`CompetitorVolumeSatuanID` = 0 OR p9.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p10.`ID` IS NULL));
UPDATE `companyproductapplication` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `application` p1 ON c.`ProductApplicationID` = p1.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`ProductApplicationID` = IF((c.`ProductApplicationID` IS NOT NULL AND (c.`ProductApplicationID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ProductApplicationID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ProductApplicationID` IS NOT NULL AND (c.`ProductApplicationID` = 0 OR p1.`ID` IS NULL));
UPDATE `companyproductassignment` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`CCBarangID` = p1.`ID`
  LEFT JOIN `satuan` p2 ON c.`CCPriceSatuanID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`CCPrincipalID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`CCVolumeSatuanID` = p4.`ID`
  LEFT JOIN `company` p5 ON c.`CompanyID` = p5.`ID`
  LEFT JOIN `companyproduct` p6 ON c.`CompanyProductID` = p6.`ID`
  LEFT JOIN `barang` p7 ON c.`CompetitorBarangID` = p7.`ID`
  LEFT JOIN `satuan` p8 ON c.`CompetitorPriceSatuanID` = p8.`ID`
  LEFT JOIN `principal` p9 ON c.`CompetitorPrincipalID` = p9.`ID`
  LEFT JOIN `satuan` p10 ON c.`CompetitorVolumeSatuanID` = p10.`ID`
  LEFT JOIN `division` p11 ON c.`DivisionID` = p11.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CCBarangID` = IF((c.`CCBarangID` IS NOT NULL AND (c.`CCBarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CCBarangID`),
       c.`CCPriceSatuanID` = IF((c.`CCPriceSatuanID` IS NOT NULL AND (c.`CCPriceSatuanID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CCPriceSatuanID`),
       c.`CCPrincipalID` = IF((c.`CCPrincipalID` IS NOT NULL AND (c.`CCPrincipalID` = 0 OR p3.`ID` IS NULL)), NULL, c.`CCPrincipalID`),
       c.`CCVolumeSatuanID` = IF((c.`CCVolumeSatuanID` IS NOT NULL AND (c.`CCVolumeSatuanID` = 0 OR p4.`ID` IS NULL)), NULL, c.`CCVolumeSatuanID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p5.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`CompanyProductID` = IF((c.`CompanyProductID` IS NOT NULL AND (c.`CompanyProductID` = 0 OR p6.`ID` IS NULL)), NULL, c.`CompanyProductID`),
       c.`CompetitorBarangID` = IF((c.`CompetitorBarangID` IS NOT NULL AND (c.`CompetitorBarangID` = 0 OR p7.`ID` IS NULL)), NULL, c.`CompetitorBarangID`),
       c.`CompetitorPriceSatuanID` = IF((c.`CompetitorPriceSatuanID` IS NOT NULL AND (c.`CompetitorPriceSatuanID` = 0 OR p8.`ID` IS NULL)), NULL, c.`CompetitorPriceSatuanID`),
       c.`CompetitorPrincipalID` = IF((c.`CompetitorPrincipalID` IS NOT NULL AND (c.`CompetitorPrincipalID` = 0 OR p9.`ID` IS NULL)), NULL, c.`CompetitorPrincipalID`),
       c.`CompetitorVolumeSatuanID` = IF((c.`CompetitorVolumeSatuanID` IS NOT NULL AND (c.`CompetitorVolumeSatuanID` = 0 OR p10.`ID` IS NULL)), NULL, c.`CompetitorVolumeSatuanID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p11.`ID` IS NULL)), NULL, c.`DivisionID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CCBarangID` IS NOT NULL AND (c.`CCBarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CCPriceSatuanID` IS NOT NULL AND (c.`CCPriceSatuanID` = 0 OR p2.`ID` IS NULL))
    OR (c.`CCPrincipalID` IS NOT NULL AND (c.`CCPrincipalID` = 0 OR p3.`ID` IS NULL))
    OR (c.`CCVolumeSatuanID` IS NOT NULL AND (c.`CCVolumeSatuanID` = 0 OR p4.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p5.`ID` IS NULL))
    OR (c.`CompanyProductID` IS NOT NULL AND (c.`CompanyProductID` = 0 OR p6.`ID` IS NULL))
    OR (c.`CompetitorBarangID` IS NOT NULL AND (c.`CompetitorBarangID` = 0 OR p7.`ID` IS NULL))
    OR (c.`CompetitorPriceSatuanID` IS NOT NULL AND (c.`CompetitorPriceSatuanID` = 0 OR p8.`ID` IS NULL))
    OR (c.`CompetitorPrincipalID` IS NOT NULL AND (c.`CompetitorPrincipalID` = 0 OR p9.`ID` IS NULL))
    OR (c.`CompetitorVolumeSatuanID` IS NOT NULL AND (c.`CompetitorVolumeSatuanID` = 0 OR p10.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p11.`ID` IS NULL));
UPDATE `companyproductassignment` c
  LEFT JOIN `users` p0 ON c.`UsersID` = p0.`ID`
   SET
       c.`UsersID` = IF((c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UsersID`)
 WHERE  (c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p0.`ID` IS NULL));
UPDATE `companyproductcategory` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `category` p1 ON c.`ProductCategoryID` = p1.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`ProductCategoryID` = IF((c.`ProductCategoryID` IS NOT NULL AND (c.`ProductCategoryID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ProductCategoryID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ProductCategoryID` IS NOT NULL AND (c.`ProductCategoryID` = 0 OR p1.`ID` IS NULL));
UPDATE `companyproduction` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `satuan` p3 ON c.`VolumeSatuanID` = p3.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`VolumeSatuanID` = IF((c.`VolumeSatuanID` IS NOT NULL AND (c.`VolumeSatuanID` = 0 OR p3.`ID` IS NULL)), NULL, c.`VolumeSatuanID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`VolumeSatuanID` IS NOT NULL AND (c.`VolumeSatuanID` = 0 OR p3.`ID` IS NULL));
UPDATE `companyproductionassignment` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `companyproduction` p2 ON c.`CompanyProductionID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UsersID` = p4.`ID`
  LEFT JOIN `satuan` p5 ON c.`VolumeSatuanID` = p5.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`CompanyProductionID` = IF((c.`CompanyProductionID` IS NOT NULL AND (c.`CompanyProductionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CompanyProductionID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`UsersID` = IF((c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p4.`ID` IS NULL)), NULL, c.`UsersID`),
       c.`VolumeSatuanID` = IF((c.`VolumeSatuanID` IS NOT NULL AND (c.`VolumeSatuanID` = 0 OR p5.`ID` IS NULL)), NULL, c.`VolumeSatuanID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CompanyProductionID` IS NOT NULL AND (c.`CompanyProductionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p4.`ID` IS NULL))
    OR (c.`VolumeSatuanID` IS NOT NULL AND (c.`VolumeSatuanID` = 0 OR p5.`ID` IS NULL));
UPDATE `companyproject` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCP` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `companyproject` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `companyprojectpriority` p5 ON c.`ProjectPriority` = p5.`ID`
  LEFT JOIN `companyprojectstatus` p6 ON c.`ProjectStatusID` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDSales` = p8.`ID`
   SET
       c.`CompanyCP` = IF((c.`CompanyCP` IS NOT NULL AND (c.`CompanyCP` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCP`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`ProjectPriority` = IF((c.`ProjectPriority` IS NOT NULL AND (c.`ProjectPriority` = 0 OR p5.`ID` IS NULL)), NULL, c.`ProjectPriority`),
       c.`ProjectStatusID` = IF((c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p6.`ID` IS NULL)), NULL, c.`ProjectStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p8.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`CompanyCP` IS NOT NULL AND (c.`CompanyCP` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p4.`ID` IS NULL))
    OR (c.`ProjectPriority` IS NOT NULL AND (c.`ProjectPriority` = 0 OR p5.`ID` IS NULL))
    OR (c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p6.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p8.`ID` IS NULL));
UPDATE `companyprojectassignment` c
  LEFT JOIN `companyprojectdetailcc` p0 ON c.`CompanyProjectDetailCCID` = p0.`ID`
  LEFT JOIN `companyprojectdetails` p1 ON c.`CompanyProjectDetailID` = p1.`ID`
  LEFT JOIN `companyproject` p2 ON c.`CompanyProjectID` = p2.`ID`
  LEFT JOIN `companyprojectstatus` p3 ON c.`ProjectStatusID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDInput` = p4.`ID`
   SET
       c.`CompanyProjectDetailCCID` = IF((c.`CompanyProjectDetailCCID` IS NOT NULL AND (c.`CompanyProjectDetailCCID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyProjectDetailCCID`),
       c.`CompanyProjectDetailID` = IF((c.`CompanyProjectDetailID` IS NOT NULL AND (c.`CompanyProjectDetailID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyProjectDetailID`),
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`ProjectStatusID` = IF((c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ProjectStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`CompanyProjectDetailCCID` IS NOT NULL AND (c.`CompanyProjectDetailCCID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyProjectDetailID` IS NOT NULL AND (c.`CompanyProjectDetailID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p4.`ID` IS NULL));
UPDATE `companyprojectdetailcc` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetails` p1 ON c.`DetailID` = p1.`ID`
  LEFT JOIN `companyprojectdetailstatusreason` p2 ON c.`ItemReasonID` = p2.`ID`
  LEFT JOIN `companyprojectdetailstatus` p3 ON c.`ItemStatusID` = p3.`ID`
  LEFT JOIN `pricetype` p4 ON c.`PriceTypeID` = p4.`ID`
  LEFT JOIN `principal` p5 ON c.`PrincipalID` = p5.`ID`
  LEFT JOIN `barang` p6 ON c.`ProductID` = p6.`ID`
  LEFT JOIN `companyprojectstatus` p7 ON c.`ProjectStatusID` = p7.`ID`
  LEFT JOIN `quantitytype` p8 ON c.`QtTypeID` = p8.`ID`
  LEFT JOIN `satuan` p9 ON c.`SatuanID` = p9.`ID`
   SET
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DetailID` = IF((c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DetailID`),
       c.`ItemReasonID` = IF((c.`ItemReasonID` IS NOT NULL AND (c.`ItemReasonID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ItemReasonID`),
       c.`ItemStatusID` = IF((c.`ItemStatusID` IS NOT NULL AND (c.`ItemStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ItemStatusID`),
       c.`PriceTypeID` = IF((c.`PriceTypeID` IS NOT NULL AND (c.`PriceTypeID` = 0 OR p4.`ID` IS NULL)), NULL, c.`PriceTypeID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p5.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p6.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`ProjectStatusID` = IF((c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p7.`ID` IS NULL)), NULL, c.`ProjectStatusID`),
       c.`QtTypeID` = IF((c.`QtTypeID` IS NOT NULL AND (c.`QtTypeID` = 0 OR p8.`ID` IS NULL)), NULL, c.`QtTypeID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p9.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ItemReasonID` IS NOT NULL AND (c.`ItemReasonID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ItemStatusID` IS NOT NULL AND (c.`ItemStatusID` = 0 OR p3.`ID` IS NULL))
    OR (c.`PriceTypeID` IS NOT NULL AND (c.`PriceTypeID` = 0 OR p4.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p5.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p6.`ID` IS NULL))
    OR (c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p7.`ID` IS NULL))
    OR (c.`QtTypeID` IS NOT NULL AND (c.`QtTypeID` = 0 OR p8.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p9.`ID` IS NULL));
UPDATE `companyprojectdetailccassignment` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetailcc` p1 ON c.`DetailCCID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `pricetype` p3 ON c.`PriceTypeID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `barang` p5 ON c.`ProductID` = p5.`ID`
  LEFT JOIN `quantitytype` p6 ON c.`QtTypeID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanID` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDInput` = p8.`ID`
   SET
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DetailCCID` = IF((c.`DetailCCID` IS NOT NULL AND (c.`DetailCCID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DetailCCID`),
       c.`DetailID` = IF((c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DetailID`),
       c.`PriceTypeID` = IF((c.`PriceTypeID` IS NOT NULL AND (c.`PriceTypeID` = 0 OR p3.`ID` IS NULL)), NULL, c.`PriceTypeID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p5.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`QtTypeID` = IF((c.`QtTypeID` IS NOT NULL AND (c.`QtTypeID` = 0 OR p6.`ID` IS NULL)), NULL, c.`QtTypeID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p7.`ID` IS NULL)), NULL, c.`SatuanID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p8.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DetailCCID` IS NOT NULL AND (c.`DetailCCID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`PriceTypeID` IS NOT NULL AND (c.`PriceTypeID` = 0 OR p3.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p5.`ID` IS NULL))
    OR (c.`QtTypeID` IS NOT NULL AND (c.`QtTypeID` = 0 OR p6.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p7.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p8.`ID` IS NULL));
UPDATE `companyprojectdetailcomp` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetails` p1 ON c.`DetailID` = p1.`ID`
  LEFT JOIN `pricetype` p2 ON c.`PriceTypeIDComp` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`PrincipalIDComp` = p3.`ID`
  LEFT JOIN `barang` p4 ON c.`ProductIDComp` = p4.`ID`
  LEFT JOIN `quantitytype` p5 ON c.`QtTypeIDComp` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`SatuanIDComp` = p6.`ID`
   SET
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DetailID` = IF((c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DetailID`),
       c.`PriceTypeIDComp` = IF((c.`PriceTypeIDComp` IS NOT NULL AND (c.`PriceTypeIDComp` = 0 OR p2.`ID` IS NULL)), NULL, c.`PriceTypeIDComp`),
       c.`PrincipalIDComp` = IF((c.`PrincipalIDComp` IS NOT NULL AND (c.`PrincipalIDComp` = 0 OR p3.`ID` IS NULL)), NULL, c.`PrincipalIDComp`),
       c.`ProductIDComp` = IF((c.`ProductIDComp` IS NOT NULL AND (c.`ProductIDComp` = 0 OR p4.`ID` IS NULL)), NULL, c.`ProductIDComp`),
       c.`QtTypeIDComp` = IF((c.`QtTypeIDComp` IS NOT NULL AND (c.`QtTypeIDComp` = 0 OR p5.`ID` IS NULL)), NULL, c.`QtTypeIDComp`),
       c.`SatuanIDComp` = IF((c.`SatuanIDComp` IS NOT NULL AND (c.`SatuanIDComp` = 0 OR p6.`ID` IS NULL)), NULL, c.`SatuanIDComp`)
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PriceTypeIDComp` IS NOT NULL AND (c.`PriceTypeIDComp` = 0 OR p2.`ID` IS NULL))
    OR (c.`PrincipalIDComp` IS NOT NULL AND (c.`PrincipalIDComp` = 0 OR p3.`ID` IS NULL))
    OR (c.`ProductIDComp` IS NOT NULL AND (c.`ProductIDComp` = 0 OR p4.`ID` IS NULL))
    OR (c.`QtTypeIDComp` IS NOT NULL AND (c.`QtTypeIDComp` = 0 OR p5.`ID` IS NULL))
    OR (c.`SatuanIDComp` IS NOT NULL AND (c.`SatuanIDComp` = 0 OR p6.`ID` IS NULL));
UPDATE `companyprojectdetailcompassignment` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetailcomp` p1 ON c.`DetailCompID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `pricetype` p3 ON c.`PriceTypeIDComp` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalIDComp` = p4.`ID`
  LEFT JOIN `barang` p5 ON c.`ProductIDComp` = p5.`ID`
  LEFT JOIN `quantitytype` p6 ON c.`QtTypeIDComp` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanIDComp` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDInput` = p8.`ID`
   SET
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DetailCompID` = IF((c.`DetailCompID` IS NOT NULL AND (c.`DetailCompID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DetailCompID`),
       c.`DetailID` = IF((c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DetailID`),
       c.`PriceTypeIDComp` = IF((c.`PriceTypeIDComp` IS NOT NULL AND (c.`PriceTypeIDComp` = 0 OR p3.`ID` IS NULL)), NULL, c.`PriceTypeIDComp`),
       c.`PrincipalIDComp` = IF((c.`PrincipalIDComp` IS NOT NULL AND (c.`PrincipalIDComp` = 0 OR p4.`ID` IS NULL)), NULL, c.`PrincipalIDComp`),
       c.`ProductIDComp` = IF((c.`ProductIDComp` IS NOT NULL AND (c.`ProductIDComp` = 0 OR p5.`ID` IS NULL)), NULL, c.`ProductIDComp`),
       c.`QtTypeIDComp` = IF((c.`QtTypeIDComp` IS NOT NULL AND (c.`QtTypeIDComp` = 0 OR p6.`ID` IS NULL)), NULL, c.`QtTypeIDComp`),
       c.`SatuanIDComp` = IF((c.`SatuanIDComp` IS NOT NULL AND (c.`SatuanIDComp` = 0 OR p7.`ID` IS NULL)), NULL, c.`SatuanIDComp`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p8.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DetailCompID` IS NOT NULL AND (c.`DetailCompID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`PriceTypeIDComp` IS NOT NULL AND (c.`PriceTypeIDComp` = 0 OR p3.`ID` IS NULL))
    OR (c.`PrincipalIDComp` IS NOT NULL AND (c.`PrincipalIDComp` = 0 OR p4.`ID` IS NULL))
    OR (c.`ProductIDComp` IS NOT NULL AND (c.`ProductIDComp` = 0 OR p5.`ID` IS NULL))
    OR (c.`QtTypeIDComp` IS NOT NULL AND (c.`QtTypeIDComp` = 0 OR p6.`ID` IS NULL))
    OR (c.`SatuanIDComp` IS NOT NULL AND (c.`SatuanIDComp` = 0 OR p7.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p8.`ID` IS NULL));
UPDATE `companyprojectdetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `companyproject` p1 ON c.`CompanyProjectID` = p1.`ID`
  LEFT JOIN `companyprojectopportunitygroup` p2 ON c.`OpportunityGroupID` = p2.`ID`
  LEFT JOIN `companyprojectstatus` p3 ON c.`ProjectStatusID` = p3.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`OpportunityGroupID` = IF((c.`OpportunityGroupID` IS NOT NULL AND (c.`OpportunityGroupID` = 0 OR p2.`ID` IS NULL)), NULL, c.`OpportunityGroupID`),
       c.`ProjectStatusID` = IF((c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ProjectStatusID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p1.`ID` IS NULL))
    OR (c.`OpportunityGroupID` IS NOT NULL AND (c.`OpportunityGroupID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p3.`ID` IS NULL));
UPDATE `companyprojectdetailsassignment` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `companyproject` p1 ON c.`CompanyProjectID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `companyprojectopportunitygroup` p3 ON c.`OpportunityGroupID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDInput` = p4.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DetailID` = IF((c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DetailID`),
       c.`OpportunityGroupID` = IF((c.`OpportunityGroupID` IS NOT NULL AND (c.`OpportunityGroupID` = 0 OR p3.`ID` IS NULL)), NULL, c.`OpportunityGroupID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`OpportunityGroupID` IS NOT NULL AND (c.`OpportunityGroupID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p4.`ID` IS NULL));
UPDATE `companyprojectdetailstatusassignment` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetailcc` p1 ON c.`DetailCCID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `companyprojectdetailstatusreason` p3 ON c.`ItemReasonID` = p3.`ID`
  LEFT JOIN `companyprojectdetailstatus` p4 ON c.`ItemStatusID` = p4.`ID`
  LEFT JOIN `companyprojectstatus` p5 ON c.`ProjectStatusID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
   SET
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DetailCCID` = IF((c.`DetailCCID` IS NOT NULL AND (c.`DetailCCID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DetailCCID`),
       c.`DetailID` = IF((c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DetailID`),
       c.`ItemReasonID` = IF((c.`ItemReasonID` IS NOT NULL AND (c.`ItemReasonID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ItemReasonID`),
       c.`ItemStatusID` = IF((c.`ItemStatusID` IS NOT NULL AND (c.`ItemStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ItemStatusID`),
       c.`ProjectStatusID` = IF((c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p5.`ID` IS NULL)), NULL, c.`ProjectStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DetailCCID` IS NOT NULL AND (c.`DetailCCID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DetailID` IS NOT NULL AND (c.`DetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ItemReasonID` IS NOT NULL AND (c.`ItemReasonID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ItemStatusID` IS NOT NULL AND (c.`ItemStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`ProjectStatusID` IS NOT NULL AND (c.`ProjectStatusID` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL));
UPDATE `companyprojectdetailstatusreason` c
  LEFT JOIN `companyprojectdetailstatus` p0 ON c.`StatusID` = p0.`ID`
   SET
       c.`StatusID` = IF((c.`StatusID` IS NOT NULL AND (c.`StatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`StatusID`)
 WHERE  (c.`StatusID` IS NOT NULL AND (c.`StatusID` = 0 OR p0.`ID` IS NULL));
UPDATE `companyprojectheaderassignment` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCP` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `companyproject` p2 ON c.`CompanyProjectID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `industry` p4 ON c.`IndustryID` = p4.`ID`
  LEFT JOIN `companyproject` p5 ON c.`ProjectID` = p5.`ID`
  LEFT JOIN `companyprojectpriority` p6 ON c.`ProjectPriority` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDSales` = p8.`ID`
   SET
       c.`CompanyCP` = IF((c.`CompanyCP` IS NOT NULL AND (c.`CompanyCP` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCP`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`CompanyProjectID` = IF((c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CompanyProjectID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p4.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p5.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`ProjectPriority` = IF((c.`ProjectPriority` IS NOT NULL AND (c.`ProjectPriority` = 0 OR p6.`ID` IS NULL)), NULL, c.`ProjectPriority`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p8.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`CompanyCP` IS NOT NULL AND (c.`CompanyCP` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CompanyProjectID` IS NOT NULL AND (c.`CompanyProjectID` = 0 OR p2.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p4.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p5.`ID` IS NULL))
    OR (c.`ProjectPriority` IS NOT NULL AND (c.`ProjectPriority` = 0 OR p6.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p8.`ID` IS NULL));
UPDATE `complain` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `complainreason` p2 ON c.`ComplainReasonID` = p2.`ID`
  LEFT JOIN `complainstatus` p3 ON c.`ComplainStatusID` = p3.`ID`
  LEFT JOIN `complaintype` p4 ON c.`ComplainTypeID` = p4.`ID`
  LEFT JOIN `division` p5 ON c.`DivisionID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDSales` = p7.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`ComplainReasonID` = IF((c.`ComplainReasonID` IS NOT NULL AND (c.`ComplainReasonID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainReasonID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`ComplainTypeID` = IF((c.`ComplainTypeID` IS NOT NULL AND (c.`ComplainTypeID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ComplainTypeID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p5.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p7.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainReasonID` IS NOT NULL AND (c.`ComplainReasonID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ComplainTypeID` IS NOT NULL AND (c.`ComplainTypeID` = 0 OR p4.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p7.`ID` IS NULL));
UPDATE `complainassignment` c
  LEFT JOIN `complain` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complainstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `complaindetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `complaindetailsstatus` p2 ON c.`ComplainDetailsStatusID` = p2.`ID`
  LEFT JOIN `complain` p3 ON c.`ComplainID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `satuan` p5 ON c.`SatuanComplainQuantityID` = p5.`ID`
  LEFT JOIN `quotationpack` p6 ON c.`SatuanPackingID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanUnitPriceUSD` = p7.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`ComplainDetailsStatusID` = IF((c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainDetailsStatusID`),
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`SatuanComplainQuantityID` = IF((c.`SatuanComplainQuantityID` IS NOT NULL AND (c.`SatuanComplainQuantityID` = 0 OR p5.`ID` IS NULL)), NULL, c.`SatuanComplainQuantityID`),
       c.`SatuanPackingID` = IF((c.`SatuanPackingID` IS NOT NULL AND (c.`SatuanPackingID` = 0 OR p6.`ID` IS NULL)), NULL, c.`SatuanPackingID`),
       c.`SatuanUnitPriceUSD` = IF((c.`SatuanUnitPriceUSD` IS NOT NULL AND (c.`SatuanUnitPriceUSD` = 0 OR p7.`ID` IS NULL)), NULL, c.`SatuanUnitPriceUSD`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p3.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL))
    OR (c.`SatuanComplainQuantityID` IS NOT NULL AND (c.`SatuanComplainQuantityID` = 0 OR p5.`ID` IS NULL))
    OR (c.`SatuanPackingID` IS NOT NULL AND (c.`SatuanPackingID` = 0 OR p6.`ID` IS NULL))
    OR (c.`SatuanUnitPriceUSD` IS NOT NULL AND (c.`SatuanUnitPriceUSD` = 0 OR p7.`ID` IS NULL));
UPDATE `complaindetailsaction` c
  LEFT JOIN `complaindetails` p0 ON c.`ComplainDetailsID` = p0.`ID`
  LEFT JOIN `complaindetailsstatus` p1 ON c.`ComplainDetailsStatusID` = p1.`ID`
  LEFT JOIN `complain` p2 ON c.`ComplainID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`ComplainDetailsID` = IF((c.`ComplainDetailsID` IS NOT NULL AND (c.`ComplainDetailsID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainDetailsID`),
       c.`ComplainDetailsStatusID` = IF((c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainDetailsStatusID`),
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`ComplainDetailsID` IS NOT NULL AND (c.`ComplainDetailsID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `complaindetailsactionassignment` c
  LEFT JOIN `complaindetailsaction` p0 ON c.`ComplainDetailsActionID` = p0.`ID`
  LEFT JOIN `complaindetails` p1 ON c.`ComplainDetailsID` = p1.`ID`
  LEFT JOIN `complaindetailsstatus` p2 ON c.`ComplainDetailsStatusID` = p2.`ID`
  LEFT JOIN `complain` p3 ON c.`ComplainID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserID` = p4.`ID`
   SET
       c.`ComplainDetailsActionID` = IF((c.`ComplainDetailsActionID` IS NOT NULL AND (c.`ComplainDetailsActionID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainDetailsActionID`),
       c.`ComplainDetailsID` = IF((c.`ComplainDetailsID` IS NOT NULL AND (c.`ComplainDetailsID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainDetailsID`),
       c.`ComplainDetailsStatusID` = IF((c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainDetailsStatusID`),
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`ComplainDetailsActionID` IS NOT NULL AND (c.`ComplainDetailsActionID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainDetailsID` IS NOT NULL AND (c.`ComplainDetailsID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p4.`ID` IS NULL));
UPDATE `complaindetailsassignment` c
  LEFT JOIN `complaindetails` p0 ON c.`ComplainDetailsID` = p0.`ID`
  LEFT JOIN `complaindetailsstatus` p1 ON c.`ComplainDetailsStatusID` = p1.`ID`
  LEFT JOIN `complain` p2 ON c.`ComplainID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`ComplainDetailsID` = IF((c.`ComplainDetailsID` IS NOT NULL AND (c.`ComplainDetailsID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainDetailsID`),
       c.`ComplainDetailsStatusID` = IF((c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainDetailsStatusID`),
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`ComplainDetailsID` IS NOT NULL AND (c.`ComplainDetailsID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND (c.`ComplainDetailsStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `complainitem` c
  LEFT JOIN `complainitemstatus` p0 ON c.`ComplainStatusID` = p0.`ID`
  LEFT JOIN `complainitemtype` p1 ON c.`ComplainTypeID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
   SET
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`ComplainTypeID` = IF((c.`ComplainTypeID` IS NOT NULL AND (c.`ComplainTypeID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainTypeID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainTypeID` IS NOT NULL AND (c.`ComplainTypeID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL));
UPDATE `complainitemassignment` c
  LEFT JOIN `complainitem` p0 ON c.`ComplainItemID` = p0.`ID`
  LEFT JOIN `complainitemstatus` p1 ON c.`ComplainItemStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`ComplainItemID` = IF((c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainItemID`),
       c.`ComplainItemStatusID` = IF((c.`ComplainItemStatusID` IS NOT NULL AND (c.`ComplainItemStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainItemStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainItemStatusID` IS NOT NULL AND (c.`ComplainItemStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `complainitemdetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `complaindetailsstatus` p3 ON c.`ComplainDetailStatusID` = p3.`ID`
  LEFT JOIN `complainitem` p4 ON c.`ComplainItemID` = p4.`ID`
  LEFT JOIN `division` p5 ON c.`DivisionID` = p5.`ID`
  LEFT JOIN `industry` p6 ON c.`IndustryID` = p6.`ID`
  LEFT JOIN `packing` p7 ON c.`PackingMonth` = p7.`ID`
  LEFT JOIN `packing` p8 ON c.`PackingYear` = p8.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p2.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`ComplainDetailStatusID` = IF((c.`ComplainDetailStatusID` IS NOT NULL AND (c.`ComplainDetailStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ComplainDetailStatusID`),
       c.`ComplainItemID` = IF((c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ComplainItemID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p5.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p6.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`PackingMonth` = IF((c.`PackingMonth` IS NOT NULL AND (c.`PackingMonth` = 0 OR p7.`ID` IS NULL)), NULL, c.`PackingMonth`),
       c.`PackingYear` = IF((c.`PackingYear` IS NOT NULL AND (c.`PackingYear` = 0 OR p8.`ID` IS NULL)), NULL, c.`PackingYear`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ComplainDetailStatusID` IS NOT NULL AND (c.`ComplainDetailStatusID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p4.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p5.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p6.`ID` IS NULL))
    OR (c.`PackingMonth` IS NOT NULL AND (c.`PackingMonth` = 0 OR p7.`ID` IS NULL))
    OR (c.`PackingYear` IS NOT NULL AND (c.`PackingYear` = 0 OR p8.`ID` IS NULL));
UPDATE `complainitemdetailsaction` c
  LEFT JOIN `complainitem` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complainitemstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `complainitemdetailsactionassignment` c
  LEFT JOIN `complainitem` p0 ON c.`ComplainItemID` = p0.`ID`
  LEFT JOIN `complainitemstatus` p1 ON c.`ComplainItemStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`ComplainItemID` = IF((c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainItemID`),
       c.`ComplainItemStatusID` = IF((c.`ComplainItemStatusID` IS NOT NULL AND (c.`ComplainItemStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainItemStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainItemStatusID` IS NOT NULL AND (c.`ComplainItemStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `complainitemdetailslot` c
  LEFT JOIN `complainitemdetails` p0 ON c.`ComplainItemDetailsID` = p0.`ID`
  LEFT JOIN `complainitem` p1 ON c.`ComplainItemID` = p1.`ID`
  LEFT JOIN `packing` p2 ON c.`PackagingID` = p2.`ID`
   SET
       c.`ComplainItemDetailsID` = IF((c.`ComplainItemDetailsID` IS NOT NULL AND (c.`ComplainItemDetailsID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainItemDetailsID`),
       c.`ComplainItemID` = IF((c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainItemID`),
       c.`PackagingID` = IF((c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PackagingID`)
 WHERE  (c.`ComplainItemDetailsID` IS NOT NULL AND (c.`ComplainItemDetailsID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p2.`ID` IS NULL));
UPDATE `complainitemdetailslotassignment` c
  LEFT JOIN `complainitemdetails` p0 ON c.`ComplainItemDetailsID` = p0.`ID`
  LEFT JOIN `complainitemdetailslot` p1 ON c.`ComplainItemDetailsLotID` = p1.`ID`
  LEFT JOIN `complainitem` p2 ON c.`ComplainItemID` = p2.`ID`
  LEFT JOIN `packing` p3 ON c.`PackagingID` = p3.`ID`
   SET
       c.`ComplainItemDetailsID` = IF((c.`ComplainItemDetailsID` IS NOT NULL AND (c.`ComplainItemDetailsID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainItemDetailsID`),
       c.`ComplainItemDetailsLotID` = IF((c.`ComplainItemDetailsLotID` IS NOT NULL AND (c.`ComplainItemDetailsLotID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainItemDetailsLotID`),
       c.`ComplainItemID` = IF((c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainItemID`),
       c.`PackagingID` = IF((c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p3.`ID` IS NULL)), NULL, c.`PackagingID`)
 WHERE  (c.`ComplainItemDetailsID` IS NOT NULL AND (c.`ComplainItemDetailsID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainItemDetailsLotID` IS NOT NULL AND (c.`ComplainItemDetailsLotID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainItemID` IS NOT NULL AND (c.`ComplainItemID` = 0 OR p2.`ID` IS NULL))
    OR (c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p3.`ID` IS NULL));
UPDATE `complaintosupplier` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `complaintosuppliertype` p2 ON c.`ComplainItemTypeID` = p2.`ID`
  LEFT JOIN `complaintosupplierstatus` p3 ON c.`ComplainStatusID` = p3.`ID`
  LEFT JOIN `complaintype` p4 ON c.`ComplainTypeID` = p4.`ID`
  LEFT JOIN `division` p5 ON c.`DivisionID` = p5.`ID`
  LEFT JOIN `industry` p6 ON c.`IndustryID` = p6.`ID`
  LEFT JOIN `packing` p7 ON c.`PackingMonth` = p7.`ID`
  LEFT JOIN `packing` p8 ON c.`PackingYear` = p8.`ID`
  LEFT JOIN `principal` p9 ON c.`PrincipalID` = p9.`ID`
  LEFT JOIN `product` p10 ON c.`ProductID` = p10.`ID`
  LEFT JOIN `users` p11 ON c.`UserIDInput` = p11.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`ComplainItemTypeID` = IF((c.`ComplainItemTypeID` IS NOT NULL AND (c.`ComplainItemTypeID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ComplainItemTypeID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`ComplainTypeID` = IF((c.`ComplainTypeID` IS NOT NULL AND (c.`ComplainTypeID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ComplainTypeID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p5.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p6.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`PackingMonth` = IF((c.`PackingMonth` IS NOT NULL AND (c.`PackingMonth` = 0 OR p7.`ID` IS NULL)), NULL, c.`PackingMonth`),
       c.`PackingYear` = IF((c.`PackingYear` IS NOT NULL AND (c.`PackingYear` = 0 OR p8.`ID` IS NULL)), NULL, c.`PackingYear`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p9.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p10.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p11.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ComplainItemTypeID` IS NOT NULL AND (c.`ComplainItemTypeID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ComplainTypeID` IS NOT NULL AND (c.`ComplainTypeID` = 0 OR p4.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p5.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p6.`ID` IS NULL))
    OR (c.`PackingMonth` IS NOT NULL AND (c.`PackingMonth` = 0 OR p7.`ID` IS NULL))
    OR (c.`PackingYear` IS NOT NULL AND (c.`PackingYear` = 0 OR p8.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p9.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p10.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p11.`ID` IS NULL));
UPDATE `complaintosupplier` c
  LEFT JOIN `users` p0 ON c.`UserIDSales` = p0.`ID`
   SET
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p0.`ID` IS NULL));
UPDATE `complaintosupplierassignment` c
  LEFT JOIN `complaintosupplier` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complaintosupplierstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `department` p2 ON c.`DepartmentID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
   SET
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`DepartmentID` = IF((c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DepartmentID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL));
UPDATE `complaintosupplierdetailsaction` c
  LEFT JOIN `complaintosupplier` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complaintosupplierstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `department` p2 ON c.`DepartementID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
   SET
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`DepartementID` = IF((c.`DepartementID` IS NOT NULL AND (c.`DepartementID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DepartementID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DepartementID` IS NOT NULL AND (c.`DepartementID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL));
UPDATE `complaintosupplierdetailsactionassignment` c
  LEFT JOIN `complaintosupplier` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complaintosupplierstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `department` p2 ON c.`DepartmentID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
   SET
       c.`ComplainID` = IF((c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ComplainID`),
       c.`ComplainStatusID` = IF((c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ComplainStatusID`),
       c.`DepartmentID` = IF((c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DepartmentID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ComplainID` IS NOT NULL AND (c.`ComplainID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ComplainStatusID` IS NOT NULL AND (c.`ComplainStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL));
UPDATE `division` c
  LEFT JOIN `groupdivision` p0 ON c.`GroupDivisionID` = p0.`ID`
   SET
       c.`GroupDivisionID` = IF((c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p0.`ID` IS NULL)), NULL, c.`GroupDivisionID`)
 WHERE  (c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p0.`ID` IS NULL));
UPDATE `documentgroupdivision` c
  LEFT JOIN `documentupload` p0 ON c.`DocID` = p0.`ID`
  LEFT JOIN `groupdivision` p1 ON c.`GroupDivID` = p1.`ID`
   SET
       c.`DocID` = IF((c.`DocID` IS NOT NULL AND (c.`DocID` = 0 OR p0.`ID` IS NULL)), NULL, c.`DocID`),
       c.`GroupDivID` = IF((c.`GroupDivID` IS NOT NULL AND (c.`GroupDivID` = 0 OR p1.`ID` IS NULL)), NULL, c.`GroupDivID`)
 WHERE  (c.`DocID` IS NOT NULL AND (c.`DocID` = 0 OR p0.`ID` IS NULL))
    OR (c.`GroupDivID` IS NOT NULL AND (c.`GroupDivID` = 0 OR p1.`ID` IS NULL));
UPDATE `documentupload` c
  LEFT JOIN `documentcategory` p0 ON c.`DocumentCategoryID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
   SET
       c.`DocumentCategoryID` = IF((c.`DocumentCategoryID` IS NOT NULL AND (c.`DocumentCategoryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`DocumentCategoryID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`DocumentCategoryID` IS NOT NULL AND (c.`DocumentCategoryID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL));
UPDATE `documentuploadinternal` c
  LEFT JOIN `documentcategory` p0 ON c.`DocumentCategoryID` = p0.`ID`
   SET
       c.`DocumentCategoryID` = IF((c.`DocumentCategoryID` IS NOT NULL AND (c.`DocumentCategoryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`DocumentCategoryID`)
 WHERE  (c.`DocumentCategoryID` IS NOT NULL AND (c.`DocumentCategoryID` = 0 OR p0.`ID` IS NULL));
UPDATE `izin` c
  LEFT JOIN `izinstatus` p0 ON c.`IzinStatusID` = p0.`ID`
  LEFT JOIN `izintype` p1 ON c.`IzinTypeID` = p1.`ID`
  LEFT JOIN `izintypestatus` p2 ON c.`IzinTypeStatusID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDSales` = p4.`ID`
   SET
       c.`IzinStatusID` = IF((c.`IzinStatusID` IS NOT NULL AND (c.`IzinStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`IzinStatusID`),
       c.`IzinTypeID` = IF((c.`IzinTypeID` IS NOT NULL AND (c.`IzinTypeID` = 0 OR p1.`ID` IS NULL)), NULL, c.`IzinTypeID`),
       c.`IzinTypeStatusID` = IF((c.`IzinTypeStatusID` IS NOT NULL AND (c.`IzinTypeStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`IzinTypeStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`IzinStatusID` IS NOT NULL AND (c.`IzinStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`IzinTypeID` IS NOT NULL AND (c.`IzinTypeID` = 0 OR p1.`ID` IS NULL))
    OR (c.`IzinTypeStatusID` IS NOT NULL AND (c.`IzinTypeStatusID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p4.`ID` IS NULL));
UPDATE `izinassignment` c
  LEFT JOIN `izin` p0 ON c.`IzinID` = p0.`ID`
  LEFT JOIN `izinstatus` p1 ON c.`IzinStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`IzinID` = IF((c.`IzinID` IS NOT NULL AND (c.`IzinID` = 0 OR p0.`ID` IS NULL)), NULL, c.`IzinID`),
       c.`IzinStatusID` = IF((c.`IzinStatusID` IS NOT NULL AND (c.`IzinStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`IzinStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`IzinID` IS NOT NULL AND (c.`IzinID` = 0 OR p0.`ID` IS NULL))
    OR (c.`IzinStatusID` IS NOT NULL AND (c.`IzinStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `izintypestatus` c
  LEFT JOIN `izintype` p0 ON c.`IzinTypeID` = p0.`ID`
   SET
       c.`IzinTypeID` = IF((c.`IzinTypeID` IS NOT NULL AND (c.`IzinTypeID` = 0 OR p0.`ID` IS NULL)), NULL, c.`IzinTypeID`)
 WHERE  (c.`IzinTypeID` IS NOT NULL AND (c.`IzinTypeID` = 0 OR p0.`ID` IS NULL));
UPDATE `labworkrequest` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `labworkrequestfeedbackstatus` p4 ON c.`LabWorkRequestFeedbackStatusID` = p4.`ID`
  LEFT JOIN `labworkrequeststatus` p5 ON c.`LabWorkRequestStatusID` = p5.`ID`
  LEFT JOIN `companyproject` p6 ON c.`ProjectID` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDProjectInitiator` = p8.`ID`
  LEFT JOIN `users` p9 ON c.`UserIDSales` = p9.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`LabWorkRequestFeedbackStatusID` = IF((c.`LabWorkRequestFeedbackStatusID` IS NOT NULL AND (c.`LabWorkRequestFeedbackStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`LabWorkRequestFeedbackStatusID`),
       c.`LabWorkRequestStatusID` = IF((c.`LabWorkRequestStatusID` IS NOT NULL AND (c.`LabWorkRequestStatusID` = 0 OR p5.`ID` IS NULL)), NULL, c.`LabWorkRequestStatusID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p6.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDProjectInitiator` = IF((c.`UserIDProjectInitiator` IS NOT NULL AND (c.`UserIDProjectInitiator` = 0 OR p8.`ID` IS NULL)), NULL, c.`UserIDProjectInitiator`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p9.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL))
    OR (c.`LabWorkRequestFeedbackStatusID` IS NOT NULL AND (c.`LabWorkRequestFeedbackStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`LabWorkRequestStatusID` IS NOT NULL AND (c.`LabWorkRequestStatusID` = 0 OR p5.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p6.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL))
    OR (c.`UserIDProjectInitiator` IS NOT NULL AND (c.`UserIDProjectInitiator` = 0 OR p8.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p9.`ID` IS NULL));
UPDATE `labworkrequestassignment` c
  LEFT JOIN `labworkrequest` p0 ON c.`LabWorkRequestID` = p0.`ID`
  LEFT JOIN `labworkrequeststatus` p1 ON c.`LabWorkRequestStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`LabWorkRequestID` = IF((c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p0.`ID` IS NULL)), NULL, c.`LabWorkRequestID`),
       c.`LabWorkRequestStatusID` = IF((c.`LabWorkRequestStatusID` IS NOT NULL AND (c.`LabWorkRequestStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`LabWorkRequestStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p0.`ID` IS NULL))
    OR (c.`LabWorkRequestStatusID` IS NOT NULL AND (c.`LabWorkRequestStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `labworkrequestdetails` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `labworkrequestdetailstatus` p1 ON c.`LabWorkRequestDetailStatusID` = p1.`ID`
  LEFT JOIN `labworkrequest` p2 ON c.`LabWorkRequestID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`PrincipalID` = p3.`ID`
  LEFT JOIN `companyprojectdetailcc` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `companyprojectdetailcomp` p5 ON c.`ProjectIDComp` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`SatuanIDUnitPrice` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanIDVolume` = p7.`ID`
  LEFT JOIN `type` p8 ON c.`TypeID` = p8.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`LabWorkRequestDetailStatusID` = IF((c.`LabWorkRequestDetailStatusID` IS NOT NULL AND (c.`LabWorkRequestDetailStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`LabWorkRequestDetailStatusID`),
       c.`LabWorkRequestID` = IF((c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p2.`ID` IS NULL)), NULL, c.`LabWorkRequestID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p3.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`ProjectIDComp` = IF((c.`ProjectIDComp` IS NOT NULL AND (c.`ProjectIDComp` = 0 OR p5.`ID` IS NULL)), NULL, c.`ProjectIDComp`),
       c.`SatuanIDUnitPrice` = IF((c.`SatuanIDUnitPrice` IS NOT NULL AND (c.`SatuanIDUnitPrice` = 0 OR p6.`ID` IS NULL)), NULL, c.`SatuanIDUnitPrice`),
       c.`SatuanIDVolume` = IF((c.`SatuanIDVolume` IS NOT NULL AND (c.`SatuanIDVolume` = 0 OR p7.`ID` IS NULL)), NULL, c.`SatuanIDVolume`),
       c.`TypeID` = IF((c.`TypeID` IS NOT NULL AND (c.`TypeID` = 0 OR p8.`ID` IS NULL)), NULL, c.`TypeID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`LabWorkRequestDetailStatusID` IS NOT NULL AND (c.`LabWorkRequestDetailStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p2.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p4.`ID` IS NULL))
    OR (c.`ProjectIDComp` IS NOT NULL AND (c.`ProjectIDComp` = 0 OR p5.`ID` IS NULL))
    OR (c.`SatuanIDUnitPrice` IS NOT NULL AND (c.`SatuanIDUnitPrice` = 0 OR p6.`ID` IS NULL))
    OR (c.`SatuanIDVolume` IS NOT NULL AND (c.`SatuanIDVolume` = 0 OR p7.`ID` IS NULL))
    OR (c.`TypeID` IS NOT NULL AND (c.`TypeID` = 0 OR p8.`ID` IS NULL));
UPDATE `labworkrequestdetailsassignment` c
  LEFT JOIN `labworkrequestdetails` p0 ON c.`LabWorkRequestDetailID` = p0.`ID`
  LEFT JOIN `labworkrequestdetailstatus` p1 ON c.`LabWorkRequestDetailStatusID` = p1.`ID`
  LEFT JOIN `labworkrequest` p2 ON c.`LabWorkRequestID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`LabWorkRequestDetailID` = IF((c.`LabWorkRequestDetailID` IS NOT NULL AND (c.`LabWorkRequestDetailID` = 0 OR p0.`ID` IS NULL)), NULL, c.`LabWorkRequestDetailID`),
       c.`LabWorkRequestDetailStatusID` = IF((c.`LabWorkRequestDetailStatusID` IS NOT NULL AND (c.`LabWorkRequestDetailStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`LabWorkRequestDetailStatusID`),
       c.`LabWorkRequestID` = IF((c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p2.`ID` IS NULL)), NULL, c.`LabWorkRequestID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`LabWorkRequestDetailID` IS NOT NULL AND (c.`LabWorkRequestDetailID` = 0 OR p0.`ID` IS NULL))
    OR (c.`LabWorkRequestDetailStatusID` IS NOT NULL AND (c.`LabWorkRequestDetailStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `labworkrequestlink` c
  LEFT JOIN `labworkrequest` p0 ON c.`LabWorkRequestID` = p0.`ID`
   SET
       c.`LabWorkRequestID` = IF((c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p0.`ID` IS NULL)), NULL, c.`LabWorkRequestID`)
 WHERE  (c.`LabWorkRequestID` IS NOT NULL AND (c.`LabWorkRequestID` = 0 OR p0.`ID` IS NULL));
UPDATE `lembur` c
  LEFT JOIN `lemburstatus` p0 ON c.`LemburStatusID` = p0.`ID`
  LEFT JOIN `lemburtype` p1 ON c.`LemburTypeID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDSales` = p3.`ID`
   SET
       c.`LemburStatusID` = IF((c.`LemburStatusID` IS NOT NULL AND (c.`LemburStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`LemburStatusID`),
       c.`LemburTypeID` = IF((c.`LemburTypeID` IS NOT NULL AND (c.`LemburTypeID` = 0 OR p1.`ID` IS NULL)), NULL, c.`LemburTypeID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`LemburStatusID` IS NOT NULL AND (c.`LemburStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`LemburTypeID` IS NOT NULL AND (c.`LemburTypeID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p3.`ID` IS NULL));
UPDATE `lemburassignment` c
  LEFT JOIN `lembur` p0 ON c.`LemburID` = p0.`ID`
  LEFT JOIN `lemburstatus` p1 ON c.`LemburStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`LemburID` = IF((c.`LemburID` IS NOT NULL AND (c.`LemburID` = 0 OR p0.`ID` IS NULL)), NULL, c.`LemburID`),
       c.`LemburStatusID` = IF((c.`LemburStatusID` IS NOT NULL AND (c.`LemburStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`LemburStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`LemburID` IS NOT NULL AND (c.`LemburID` = 0 OR p0.`ID` IS NULL))
    OR (c.`LemburStatusID` IS NOT NULL AND (c.`LemburStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `menu` c
  LEFT JOIN `menu` p0 ON c.`ParentID` = p0.`ID`
   SET
       c.`ParentID` = IF((c.`ParentID` IS NOT NULL AND (c.`ParentID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ParentID`)
 WHERE  (c.`ParentID` IS NOT NULL AND (c.`ParentID` = 0 OR p0.`ID` IS NULL));
UPDATE `news` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL));
UPDATE `onleave` c
  LEFT JOIN `onleavelimit` p0 ON c.`OnLeaveLimitID` = p0.`ID`
  LEFT JOIN `onleavestatus` p1 ON c.`OnLeaveStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDSales` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserPengganti1` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserPengganti2` = p5.`ID`
   SET
       c.`OnLeaveLimitID` = IF((c.`OnLeaveLimitID` IS NOT NULL AND (c.`OnLeaveLimitID` = 0 OR p0.`ID` IS NULL)), NULL, c.`OnLeaveLimitID`),
       c.`OnLeaveStatusID` = IF((c.`OnLeaveStatusID` IS NOT NULL AND (c.`OnLeaveStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`OnLeaveStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserIDSales`),
       c.`UserPengganti1` = IF((c.`UserPengganti1` IS NOT NULL AND (c.`UserPengganti1` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserPengganti1`),
       c.`UserPengganti2` = IF((c.`UserPengganti2` IS NOT NULL AND (c.`UserPengganti2` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserPengganti2`)
 WHERE  (c.`OnLeaveLimitID` IS NOT NULL AND (c.`OnLeaveLimitID` = 0 OR p0.`ID` IS NULL))
    OR (c.`OnLeaveStatusID` IS NOT NULL AND (c.`OnLeaveStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserPengganti1` IS NOT NULL AND (c.`UserPengganti1` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserPengganti2` IS NOT NULL AND (c.`UserPengganti2` = 0 OR p5.`ID` IS NULL));
UPDATE `onleaveadditional` c
  LEFT JOIN `onleavelimit` p0 ON c.`OnLeaveLimitID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`OnLeaveLimitID` = IF((c.`OnLeaveLimitID` IS NOT NULL AND (c.`OnLeaveLimitID` = 0 OR p0.`ID` IS NULL)), NULL, c.`OnLeaveLimitID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`OnLeaveLimitID` IS NOT NULL AND (c.`OnLeaveLimitID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `onleaveadditionalassignment` c
  LEFT JOIN `onleaveadditional` p0 ON c.`OnLeaveAdditionalID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`OnLeaveAdditionalID` = IF((c.`OnLeaveAdditionalID` IS NOT NULL AND (c.`OnLeaveAdditionalID` = 0 OR p0.`ID` IS NULL)), NULL, c.`OnLeaveAdditionalID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`OnLeaveAdditionalID` IS NOT NULL AND (c.`OnLeaveAdditionalID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `onleaveassignment` c
  LEFT JOIN `onleave` p0 ON c.`OnLeaveID` = p0.`ID`
  LEFT JOIN `onleavestatus` p1 ON c.`OnLeaveStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`OnLeaveID` = IF((c.`OnLeaveID` IS NOT NULL AND (c.`OnLeaveID` = 0 OR p0.`ID` IS NULL)), NULL, c.`OnLeaveID`),
       c.`OnLeaveStatusID` = IF((c.`OnLeaveStatusID` IS NOT NULL AND (c.`OnLeaveStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`OnLeaveStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`OnLeaveID` IS NOT NULL AND (c.`OnLeaveID` = 0 OR p0.`ID` IS NULL))
    OR (c.`OnLeaveStatusID` IS NOT NULL AND (c.`OnLeaveStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `packing` c
  LEFT JOIN `satuan` p0 ON c.`SatuanID` = p0.`ID`
   SET
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p0.`ID` IS NULL));
UPDATE `potentialsales` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL));
UPDATE `potentialsaleshistory` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `potentialsales` p2 ON c.`PotentialSalesID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`PrincipalID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserID` = p4.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`PotentialSalesID` = IF((c.`PotentialSalesID` IS NOT NULL AND (c.`PotentialSalesID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PotentialSalesID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p3.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PotentialSalesID` IS NOT NULL AND (c.`PotentialSalesID` = 0 OR p2.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p4.`ID` IS NULL));
UPDATE `principalcp` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
   SET
       c.`AddressType` = IF((c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL)), NULL, c.`AddressType`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL));
UPDATE `principalcpassignment` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `principalcp` p1 ON c.`PrincipalCPID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UsersID` = p3.`ID`
   SET
       c.`AddressType` = IF((c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL)), NULL, c.`AddressType`),
       c.`PrincipalCPID` = IF((c.`PrincipalCPID` IS NOT NULL AND (c.`PrincipalCPID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalCPID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UsersID` = IF((c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UsersID`)
 WHERE  (c.`AddressType` IS NOT NULL AND (c.`AddressType` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalCPID` IS NOT NULL AND (c.`PrincipalCPID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UsersID` IS NOT NULL AND (c.`UsersID` = 0 OR p3.`ID` IS NULL));
UPDATE `principalfaq` c
  LEFT JOIN `principal` p0 ON c.`PrincipalID` = p0.`ID`
   SET
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL));
UPDATE `principalfaqhistory` c
  LEFT JOIN `principalfaq` p0 ON c.`PrincipalFAQID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
   SET
       c.`PrincipalFAQID` = IF((c.`PrincipalFAQID` IS NOT NULL AND (c.`PrincipalFAQID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PrincipalFAQID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`PrincipalFAQID` IS NOT NULL AND (c.`PrincipalFAQID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL));
UPDATE `printeditemfulfillment` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL));
UPDATE `product` c
  LEFT JOIN `class` p0 ON c.`ClassID` = p0.`ID`
  LEFT JOIN `packing` p1 ON c.`PackingID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
   SET
       c.`ClassID` = IF((c.`ClassID` IS NOT NULL AND (c.`ClassID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ClassID`),
       c.`PackingID` = IF((c.`PackingID` IS NOT NULL AND (c.`PackingID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PackingID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PrincipalID`)
 WHERE  (c.`ClassID` IS NOT NULL AND (c.`ClassID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PackingID` IS NOT NULL AND (c.`PackingID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL));
UPDATE `productapplication` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`ProductID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `productcategory` c
  LEFT JOIN `category` p0 ON c.`CategoryID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`ProductID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`CategoryID` = IF((c.`CategoryID` IS NOT NULL AND (c.`CategoryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CategoryID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`CategoryID` IS NOT NULL AND (c.`CategoryID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `proposedcreditceiling` c
  LEFT JOIN `creditceilingstatus` p0 ON c.`CCStatusID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `justification` p2 ON c.`JustificationID` = p2.`ID`
  LEFT JOIN `quotationpaymentterm` p3 ON c.`QuotationPaymentTermApprovedID` = p3.`ID`
  LEFT JOIN `quotationpaymentterm` p4 ON c.`QuotationPaymentTermID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
   SET
       c.`CCStatusID` = IF((c.`CCStatusID` IS NOT NULL AND (c.`CCStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CCStatusID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`JustificationID` = IF((c.`JustificationID` IS NOT NULL AND (c.`JustificationID` = 0 OR p2.`ID` IS NULL)), NULL, c.`JustificationID`),
       c.`QuotationPaymentTermApprovedID` = IF((c.`QuotationPaymentTermApprovedID` IS NOT NULL AND (c.`QuotationPaymentTermApprovedID` = 0 OR p3.`ID` IS NULL)), NULL, c.`QuotationPaymentTermApprovedID`),
       c.`QuotationPaymentTermID` = IF((c.`QuotationPaymentTermID` IS NOT NULL AND (c.`QuotationPaymentTermID` = 0 OR p4.`ID` IS NULL)), NULL, c.`QuotationPaymentTermID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`CCStatusID` IS NOT NULL AND (c.`CCStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`JustificationID` IS NOT NULL AND (c.`JustificationID` = 0 OR p2.`ID` IS NULL))
    OR (c.`QuotationPaymentTermApprovedID` IS NOT NULL AND (c.`QuotationPaymentTermApprovedID` = 0 OR p3.`ID` IS NULL))
    OR (c.`QuotationPaymentTermID` IS NOT NULL AND (c.`QuotationPaymentTermID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL));
UPDATE `proposedcreditceilinghistory` c
  LEFT JOIN `creditceilingstatus` p0 ON c.`CCStatusID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `justification` p2 ON c.`JustificationID` = p2.`ID`
  LEFT JOIN `proposedcreditceiling` p3 ON c.`ProposedCCID` = p3.`ID`
  LEFT JOIN `quotationpaymentterm` p4 ON c.`QuotationPaymentTermApprovedID` = p4.`ID`
  LEFT JOIN `quotationpaymentterm` p5 ON c.`QuotationPaymentTermID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserID` = p6.`ID`
   SET
       c.`CCStatusID` = IF((c.`CCStatusID` IS NOT NULL AND (c.`CCStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CCStatusID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`JustificationID` = IF((c.`JustificationID` IS NOT NULL AND (c.`JustificationID` = 0 OR p2.`ID` IS NULL)), NULL, c.`JustificationID`),
       c.`ProposedCCID` = IF((c.`ProposedCCID` IS NOT NULL AND (c.`ProposedCCID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ProposedCCID`),
       c.`QuotationPaymentTermApprovedID` = IF((c.`QuotationPaymentTermApprovedID` IS NOT NULL AND (c.`QuotationPaymentTermApprovedID` = 0 OR p4.`ID` IS NULL)), NULL, c.`QuotationPaymentTermApprovedID`),
       c.`QuotationPaymentTermID` = IF((c.`QuotationPaymentTermID` IS NOT NULL AND (c.`QuotationPaymentTermID` = 0 OR p5.`ID` IS NULL)), NULL, c.`QuotationPaymentTermID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`CCStatusID` IS NOT NULL AND (c.`CCStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`JustificationID` IS NOT NULL AND (c.`JustificationID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ProposedCCID` IS NOT NULL AND (c.`ProposedCCID` = 0 OR p3.`ID` IS NULL))
    OR (c.`QuotationPaymentTermApprovedID` IS NOT NULL AND (c.`QuotationPaymentTermApprovedID` = 0 OR p4.`ID` IS NULL))
    OR (c.`QuotationPaymentTermID` IS NOT NULL AND (c.`QuotationPaymentTermID` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p6.`ID` IS NULL));
UPDATE `purchaseorder` c
  LEFT JOIN `purchaseorderstatus` p0 ON c.`PurchaseOrderStatusID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDInput` = p1.`ID`
   SET
       c.`PurchaseOrderStatusID` = IF((c.`PurchaseOrderStatusID` IS NOT NULL AND (c.`PurchaseOrderStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PurchaseOrderStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`PurchaseOrderStatusID` IS NOT NULL AND (c.`PurchaseOrderStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p1.`ID` IS NULL));
UPDATE `purchaseorderassignment` c
  LEFT JOIN `purchaseorder` p0 ON c.`PurchaseOrderID` = p0.`ID`
  LEFT JOIN `purchaseorderstatus` p1 ON c.`PurchaseOrderStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`PurchaseOrderID` = IF((c.`PurchaseOrderID` IS NOT NULL AND (c.`PurchaseOrderID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PurchaseOrderID`),
       c.`PurchaseOrderStatusID` = IF((c.`PurchaseOrderStatusID` IS NOT NULL AND (c.`PurchaseOrderStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PurchaseOrderStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`PurchaseOrderID` IS NOT NULL AND (c.`PurchaseOrderID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PurchaseOrderStatusID` IS NOT NULL AND (c.`PurchaseOrderStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `purchaseorderdetails` c
  LEFT JOIN `packing` p0 ON c.`PackingID` = p0.`ID`
  LEFT JOIN `purchaseorderstatus` p1 ON c.`PurchaseOrderDetailStatusID` = p1.`ID`
  LEFT JOIN `purchaseorder` p2 ON c.`PurchaseOrderID` = p2.`ID`
  LEFT JOIN `satuan` p3 ON c.`SatuanID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`SatuanOrderQtyID` = p4.`ID`
   SET
       c.`PackingID` = IF((c.`PackingID` IS NOT NULL AND (c.`PackingID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PackingID`),
       c.`PurchaseOrderDetailStatusID` = IF((c.`PurchaseOrderDetailStatusID` IS NOT NULL AND (c.`PurchaseOrderDetailStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PurchaseOrderDetailStatusID`),
       c.`PurchaseOrderID` = IF((c.`PurchaseOrderID` IS NOT NULL AND (c.`PurchaseOrderID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PurchaseOrderID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p3.`ID` IS NULL)), NULL, c.`SatuanID`),
       c.`SatuanOrderQtyID` = IF((c.`SatuanOrderQtyID` IS NOT NULL AND (c.`SatuanOrderQtyID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SatuanOrderQtyID`)
 WHERE  (c.`PackingID` IS NOT NULL AND (c.`PackingID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PurchaseOrderDetailStatusID` IS NOT NULL AND (c.`PurchaseOrderDetailStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PurchaseOrderID` IS NOT NULL AND (c.`PurchaseOrderID` = 0 OR p2.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SatuanOrderQtyID` IS NOT NULL AND (c.`SatuanOrderQtyID` = 0 OR p4.`ID` IS NULL));
UPDATE `purchaseorderdetailsassignment` c
  LEFT JOIN `purchaseorderdetails` p0 ON c.`PurchaseOrderDetailID` = p0.`ID`
  LEFT JOIN `purchaseorder` p1 ON c.`PurchaseOrderID` = p1.`ID`
  LEFT JOIN `purchaseorderstatus` p2 ON c.`PurchaseOrderStatusID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`PurchaseOrderDetailID` = IF((c.`PurchaseOrderDetailID` IS NOT NULL AND (c.`PurchaseOrderDetailID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PurchaseOrderDetailID`),
       c.`PurchaseOrderID` = IF((c.`PurchaseOrderID` IS NOT NULL AND (c.`PurchaseOrderID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PurchaseOrderID`),
       c.`PurchaseOrderStatusID` = IF((c.`PurchaseOrderStatusID` IS NOT NULL AND (c.`PurchaseOrderStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PurchaseOrderStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`PurchaseOrderDetailID` IS NOT NULL AND (c.`PurchaseOrderDetailID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PurchaseOrderID` IS NOT NULL AND (c.`PurchaseOrderID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PurchaseOrderStatusID` IS NOT NULL AND (c.`PurchaseOrderStatusID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `purchaseorderhargajual` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL));
UPDATE `quotation` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `companycp` p2 ON c.`DeliveryAddressID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `companycp` p4 ON c.`InvoiceAddressID` = p4.`ID`
  LEFT JOIN `quotationdeliverytime` p5 ON c.`QuotationDeliveryTimeID` = p5.`ID`
  LEFT JOIN `quotationfeedbackstatus` p6 ON c.`QuotationFeedbackStatusID` = p6.`ID`
  LEFT JOIN `quotationpaymentterm` p7 ON c.`QuotationPaymentTermID` = p7.`ID`
  LEFT JOIN `quotationpricedesc` p8 ON c.`QuotationPriceDescID` = p8.`ID`
  LEFT JOIN `quotationsalesterm` p9 ON c.`QuotationSalesTermID` = p9.`ID`
  LEFT JOIN `quotationstatus` p10 ON c.`QuotationStatusID` = p10.`ID`
  LEFT JOIN `quotationstockavailability` p11 ON c.`QuotationStockAvailibilityID` = p11.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DeliveryAddressID` = IF((c.`DeliveryAddressID` IS NOT NULL AND (c.`DeliveryAddressID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DeliveryAddressID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`InvoiceAddressID` = IF((c.`InvoiceAddressID` IS NOT NULL AND (c.`InvoiceAddressID` = 0 OR p4.`ID` IS NULL)), NULL, c.`InvoiceAddressID`),
       c.`QuotationDeliveryTimeID` = IF((c.`QuotationDeliveryTimeID` IS NOT NULL AND (c.`QuotationDeliveryTimeID` = 0 OR p5.`ID` IS NULL)), NULL, c.`QuotationDeliveryTimeID`),
       c.`QuotationFeedbackStatusID` = IF((c.`QuotationFeedbackStatusID` IS NOT NULL AND (c.`QuotationFeedbackStatusID` = 0 OR p6.`ID` IS NULL)), NULL, c.`QuotationFeedbackStatusID`),
       c.`QuotationPaymentTermID` = IF((c.`QuotationPaymentTermID` IS NOT NULL AND (c.`QuotationPaymentTermID` = 0 OR p7.`ID` IS NULL)), NULL, c.`QuotationPaymentTermID`),
       c.`QuotationPriceDescID` = IF((c.`QuotationPriceDescID` IS NOT NULL AND (c.`QuotationPriceDescID` = 0 OR p8.`ID` IS NULL)), NULL, c.`QuotationPriceDescID`),
       c.`QuotationSalesTermID` = IF((c.`QuotationSalesTermID` IS NOT NULL AND (c.`QuotationSalesTermID` = 0 OR p9.`ID` IS NULL)), NULL, c.`QuotationSalesTermID`),
       c.`QuotationStatusID` = IF((c.`QuotationStatusID` IS NOT NULL AND (c.`QuotationStatusID` = 0 OR p10.`ID` IS NULL)), NULL, c.`QuotationStatusID`),
       c.`QuotationStockAvailibilityID` = IF((c.`QuotationStockAvailibilityID` IS NOT NULL AND (c.`QuotationStockAvailibilityID` = 0 OR p11.`ID` IS NULL)), NULL, c.`QuotationStockAvailibilityID`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DeliveryAddressID` IS NOT NULL AND (c.`DeliveryAddressID` = 0 OR p2.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL))
    OR (c.`InvoiceAddressID` IS NOT NULL AND (c.`InvoiceAddressID` = 0 OR p4.`ID` IS NULL))
    OR (c.`QuotationDeliveryTimeID` IS NOT NULL AND (c.`QuotationDeliveryTimeID` = 0 OR p5.`ID` IS NULL))
    OR (c.`QuotationFeedbackStatusID` IS NOT NULL AND (c.`QuotationFeedbackStatusID` = 0 OR p6.`ID` IS NULL))
    OR (c.`QuotationPaymentTermID` IS NOT NULL AND (c.`QuotationPaymentTermID` = 0 OR p7.`ID` IS NULL))
    OR (c.`QuotationPriceDescID` IS NOT NULL AND (c.`QuotationPriceDescID` = 0 OR p8.`ID` IS NULL))
    OR (c.`QuotationSalesTermID` IS NOT NULL AND (c.`QuotationSalesTermID` = 0 OR p9.`ID` IS NULL))
    OR (c.`QuotationStatusID` IS NOT NULL AND (c.`QuotationStatusID` = 0 OR p10.`ID` IS NULL))
    OR (c.`QuotationStockAvailibilityID` IS NOT NULL AND (c.`QuotationStockAvailibilityID` = 0 OR p11.`ID` IS NULL));
UPDATE `quotation` c
  LEFT JOIN `quotationsubject` p0 ON c.`QuotationSubjectID` = p0.`ID`
  LEFT JOIN `quotationtitle` p1 ON c.`QuotationTitleID` = p1.`ID`
  LEFT JOIN `quotationtype` p2 ON c.`QuotationTypeID` = p2.`ID`
  LEFT JOIN `quotationvalidity` p3 ON c.`QuotationValidityID` = p3.`ID`
  LEFT JOIN `quotation` p4 ON c.`ReferenceQuotationID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
   SET
       c.`QuotationSubjectID` = IF((c.`QuotationSubjectID` IS NOT NULL AND (c.`QuotationSubjectID` = 0 OR p0.`ID` IS NULL)), NULL, c.`QuotationSubjectID`),
       c.`QuotationTitleID` = IF((c.`QuotationTitleID` IS NOT NULL AND (c.`QuotationTitleID` = 0 OR p1.`ID` IS NULL)), NULL, c.`QuotationTitleID`),
       c.`QuotationTypeID` = IF((c.`QuotationTypeID` IS NOT NULL AND (c.`QuotationTypeID` = 0 OR p2.`ID` IS NULL)), NULL, c.`QuotationTypeID`),
       c.`QuotationValidityID` = IF((c.`QuotationValidityID` IS NOT NULL AND (c.`QuotationValidityID` = 0 OR p3.`ID` IS NULL)), NULL, c.`QuotationValidityID`),
       c.`ReferenceQuotationID` = IF((c.`ReferenceQuotationID` IS NOT NULL AND (c.`ReferenceQuotationID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ReferenceQuotationID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`QuotationSubjectID` IS NOT NULL AND (c.`QuotationSubjectID` = 0 OR p0.`ID` IS NULL))
    OR (c.`QuotationTitleID` IS NOT NULL AND (c.`QuotationTitleID` = 0 OR p1.`ID` IS NULL))
    OR (c.`QuotationTypeID` IS NOT NULL AND (c.`QuotationTypeID` = 0 OR p2.`ID` IS NULL))
    OR (c.`QuotationValidityID` IS NOT NULL AND (c.`QuotationValidityID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ReferenceQuotationID` IS NOT NULL AND (c.`ReferenceQuotationID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p6.`ID` IS NULL));
UPDATE `quotationassignment` c
  LEFT JOIN `quotation` p0 ON c.`QuotationID` = p0.`ID`
  LEFT JOIN `quotationstatus` p1 ON c.`QuotationStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`QuotationID` = IF((c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`QuotationID`),
       c.`QuotationStatusID` = IF((c.`QuotationStatusID` IS NOT NULL AND (c.`QuotationStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`QuotationStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`QuotationStatusID` IS NOT NULL AND (c.`QuotationStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `quotationdetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `packing` p2 ON c.`PackingID` = p2.`ID`
  LEFT JOIN `companyprojectdetailcc` p3 ON c.`ProjectID` = p3.`ID`
  LEFT JOIN `quotationdetailstatus` p4 ON c.`QuotationDetailStatusID` = p4.`ID`
  LEFT JOIN `quotation` p5 ON c.`QuotationID` = p5.`ID`
  LEFT JOIN `quotationpack` p6 ON c.`QuotationPackID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanID` = p7.`ID`
  LEFT JOIN `satuan` p8 ON c.`SatuanOrderQty` = p8.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`PackingID` = IF((c.`PackingID` IS NOT NULL AND (c.`PackingID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PackingID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`QuotationDetailStatusID` = IF((c.`QuotationDetailStatusID` IS NOT NULL AND (c.`QuotationDetailStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`QuotationDetailStatusID`),
       c.`QuotationID` = IF((c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p5.`ID` IS NULL)), NULL, c.`QuotationID`),
       c.`QuotationPackID` = IF((c.`QuotationPackID` IS NOT NULL AND (c.`QuotationPackID` = 0 OR p6.`ID` IS NULL)), NULL, c.`QuotationPackID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p7.`ID` IS NULL)), NULL, c.`SatuanID`),
       c.`SatuanOrderQty` = IF((c.`SatuanOrderQty` IS NOT NULL AND (c.`SatuanOrderQty` = 0 OR p8.`ID` IS NULL)), NULL, c.`SatuanOrderQty`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PackingID` IS NOT NULL AND (c.`PackingID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p3.`ID` IS NULL))
    OR (c.`QuotationDetailStatusID` IS NOT NULL AND (c.`QuotationDetailStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p5.`ID` IS NULL))
    OR (c.`QuotationPackID` IS NOT NULL AND (c.`QuotationPackID` = 0 OR p6.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p7.`ID` IS NULL))
    OR (c.`SatuanOrderQty` IS NOT NULL AND (c.`SatuanOrderQty` = 0 OR p8.`ID` IS NULL));
UPDATE `quotationdetailsassignment` c
  LEFT JOIN `quotationdetails` p0 ON c.`QuotationDetailID` = p0.`ID`
  LEFT JOIN `quotationdetailstatus` p1 ON c.`QuotationDetailStatusID` = p1.`ID`
  LEFT JOIN `quotation` p2 ON c.`QuotationID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`QuotationDetailID` = IF((c.`QuotationDetailID` IS NOT NULL AND (c.`QuotationDetailID` = 0 OR p0.`ID` IS NULL)), NULL, c.`QuotationDetailID`),
       c.`QuotationDetailStatusID` = IF((c.`QuotationDetailStatusID` IS NOT NULL AND (c.`QuotationDetailStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`QuotationDetailStatusID`),
       c.`QuotationID` = IF((c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p2.`ID` IS NULL)), NULL, c.`QuotationID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`QuotationDetailID` IS NOT NULL AND (c.`QuotationDetailID` = 0 OR p0.`ID` IS NULL))
    OR (c.`QuotationDetailStatusID` IS NOT NULL AND (c.`QuotationDetailStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `quotationlink` c
  LEFT JOIN `quotation` p0 ON c.`QuotationID` = p0.`ID`
   SET
       c.`QuotationID` = IF((c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`QuotationID`)
 WHERE  (c.`QuotationID` IS NOT NULL AND (c.`QuotationID` = 0 OR p0.`ID` IS NULL));
UPDATE `reference` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL));
UPDATE `referencehistory` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `reference` p1 ON c.`ReferenceID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`ReferenceID` = IF((c.`ReferenceID` IS NOT NULL AND (c.`ReferenceID` = 0 OR p1.`ID` IS NULL)), NULL, c.`ReferenceID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`ReferenceID` IS NOT NULL AND (c.`ReferenceID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `relabelhistory` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL));
UPDATE `rolegadget` c
  LEFT JOIN `gadget` p0 ON c.`GadgetID` = p0.`ID`
  LEFT JOIN `role` p1 ON c.`RoleID` = p1.`ID`
   SET
       c.`GadgetID` = IF((c.`GadgetID` IS NOT NULL AND (c.`GadgetID` = 0 OR p0.`ID` IS NULL)), NULL, c.`GadgetID`),
       c.`RoleID` = IF((c.`RoleID` IS NOT NULL AND (c.`RoleID` = 0 OR p1.`ID` IS NULL)), NULL, c.`RoleID`)
 WHERE  (c.`GadgetID` IS NOT NULL AND (c.`GadgetID` = 0 OR p0.`ID` IS NULL))
    OR (c.`RoleID` IS NOT NULL AND (c.`RoleID` = 0 OR p1.`ID` IS NULL));
UPDATE `rolemenu` c
  LEFT JOIN `menu` p0 ON c.`MenuID` = p0.`ID`
  LEFT JOIN `role` p1 ON c.`RoleID` = p1.`ID`
   SET
       c.`MenuID` = IF((c.`MenuID` IS NOT NULL AND (c.`MenuID` = 0 OR p0.`ID` IS NULL)), NULL, c.`MenuID`),
       c.`RoleID` = IF((c.`RoleID` IS NOT NULL AND (c.`RoleID` = 0 OR p1.`ID` IS NULL)), NULL, c.`RoleID`)
 WHERE  (c.`MenuID` IS NOT NULL AND (c.`MenuID` = 0 OR p0.`ID` IS NULL))
    OR (c.`RoleID` IS NOT NULL AND (c.`RoleID` = 0 OR p1.`ID` IS NULL));
UPDATE `salesrebate` c
  LEFT JOIN `quotationpaymentterm` p0 ON c.`CCPaymentTerm` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `salesrebate` p4 ON c.`ReferenceRebateID` = p4.`ID`
  LEFT JOIN `salesrebatestatus` p5 ON c.`SalesRebateStatusID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDSales` = p7.`ID`
   SET
       c.`CCPaymentTerm` = IF((c.`CCPaymentTerm` IS NOT NULL AND (c.`CCPaymentTerm` = 0 OR p0.`ID` IS NULL)), NULL, c.`CCPaymentTerm`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`ReferenceRebateID` = IF((c.`ReferenceRebateID` IS NOT NULL AND (c.`ReferenceRebateID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ReferenceRebateID`),
       c.`SalesRebateStatusID` = IF((c.`SalesRebateStatusID` IS NOT NULL AND (c.`SalesRebateStatusID` = 0 OR p5.`ID` IS NULL)), NULL, c.`SalesRebateStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p7.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`CCPaymentTerm` IS NOT NULL AND (c.`CCPaymentTerm` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p3.`ID` IS NULL))
    OR (c.`ReferenceRebateID` IS NOT NULL AND (c.`ReferenceRebateID` = 0 OR p4.`ID` IS NULL))
    OR (c.`SalesRebateStatusID` IS NOT NULL AND (c.`SalesRebateStatusID` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p7.`ID` IS NULL));
UPDATE `salesrebateassignment` c
  LEFT JOIN `salesrebate` p0 ON c.`SalesRebateID` = p0.`ID`
  LEFT JOIN `salesrebatestatus` p1 ON c.`SalesRebateStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`SalesRebateID` = IF((c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SalesRebateID`),
       c.`SalesRebateStatusID` = IF((c.`SalesRebateStatusID` IS NOT NULL AND (c.`SalesRebateStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SalesRebateStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SalesRebateStatusID` IS NOT NULL AND (c.`SalesRebateStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `salesrebatedetail` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `salesrebate` p1 ON c.`SalesRebateID` = p1.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`SalesRebateID` = IF((c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SalesRebateID`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p1.`ID` IS NULL));
UPDATE `salesrebateinvoice` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `division` p1 ON c.`DivisionID` = p1.`ID`
  LEFT JOIN `industry` p2 ON c.`IndustryID` = p2.`ID`
  LEFT JOIN `salesrebate` p3 ON c.`SalesRebateID` = p3.`ID`
  LEFT JOIN `salesrebateinvoicedetailstatus` p4 ON c.`SalesRebateInvoiceStatusID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserInput` = p5.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p2.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`SalesRebateID` = IF((c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p3.`ID` IS NULL)), NULL, c.`SalesRebateID`),
       c.`SalesRebateInvoiceStatusID` = IF((c.`SalesRebateInvoiceStatusID` IS NOT NULL AND (c.`SalesRebateInvoiceStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SalesRebateInvoiceStatusID`),
       c.`UserInput` = IF((c.`UserInput` IS NOT NULL AND (c.`UserInput` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserInput`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p1.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p2.`ID` IS NULL))
    OR (c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SalesRebateInvoiceStatusID` IS NOT NULL AND (c.`SalesRebateInvoiceStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserInput` IS NOT NULL AND (c.`UserInput` = 0 OR p5.`ID` IS NULL));
UPDATE `salesrebateinvoiceassignment` c
  LEFT JOIN `salesrebateinvoice` p0 ON c.`SalesRebateInvoiceID` = p0.`ID`
  LEFT JOIN `salesrebateinvoicedetailstatus` p1 ON c.`SalesRebateInvoiceStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
   SET
       c.`SalesRebateInvoiceID` = IF((c.`SalesRebateInvoiceID` IS NOT NULL AND (c.`SalesRebateInvoiceID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SalesRebateInvoiceID`),
       c.`SalesRebateInvoiceStatusID` = IF((c.`SalesRebateInvoiceStatusID` IS NOT NULL AND (c.`SalesRebateInvoiceStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SalesRebateInvoiceStatusID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`SalesRebateInvoiceID` IS NOT NULL AND (c.`SalesRebateInvoiceID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SalesRebateInvoiceStatusID` IS NOT NULL AND (c.`SalesRebateInvoiceStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p2.`ID` IS NULL));
UPDATE `salesrebateinvoicedetail` c
  LEFT JOIN `companycp` p0 ON c.`PaymentCPID` = p0.`ID`
  LEFT JOIN `salesrebate` p1 ON c.`SalesRebateID` = p1.`ID`
  LEFT JOIN `salesrebateinvoicedetailstatus` p2 ON c.`SalesRebateInvoiceDetailStatusID` = p2.`ID`
  LEFT JOIN `salesrebateinvoice` p3 ON c.`SalesRebateInvoiceID` = p3.`ID`
   SET
       c.`PaymentCPID` = IF((c.`PaymentCPID` IS NOT NULL AND (c.`PaymentCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PaymentCPID`),
       c.`SalesRebateID` = IF((c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SalesRebateID`),
       c.`SalesRebateInvoiceDetailStatusID` = IF((c.`SalesRebateInvoiceDetailStatusID` IS NOT NULL AND (c.`SalesRebateInvoiceDetailStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`SalesRebateInvoiceDetailStatusID`),
       c.`SalesRebateInvoiceID` = IF((c.`SalesRebateInvoiceID` IS NOT NULL AND (c.`SalesRebateInvoiceID` = 0 OR p3.`ID` IS NULL)), NULL, c.`SalesRebateInvoiceID`)
 WHERE  (c.`PaymentCPID` IS NOT NULL AND (c.`PaymentCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SalesRebateID` IS NOT NULL AND (c.`SalesRebateID` = 0 OR p1.`ID` IS NULL))
    OR (c.`SalesRebateInvoiceDetailStatusID` IS NOT NULL AND (c.`SalesRebateInvoiceDetailStatusID` = 0 OR p2.`ID` IS NULL))
    OR (c.`SalesRebateInvoiceID` IS NOT NULL AND (c.`SalesRebateInvoiceID` = 0 OR p3.`ID` IS NULL));
UPDATE `salesrebateinvoicepaymentdetail` c
  LEFT JOIN `salesrebateinvoicedetail` p0 ON c.`SalesRebateInvoiceDetailID` = p0.`ID`
   SET
       c.`SalesRebateInvoiceDetailID` = IF((c.`SalesRebateInvoiceDetailID` IS NOT NULL AND (c.`SalesRebateInvoiceDetailID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SalesRebateInvoiceDetailID`)
 WHERE  (c.`SalesRebateInvoiceDetailID` IS NOT NULL AND (c.`SalesRebateInvoiceDetailID` = 0 OR p0.`ID` IS NULL));
UPDATE `sampleorder` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `delivery` p2 ON c.`DeliveryID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `industry` p4 ON c.`IndustryID` = p4.`ID`
  LEFT JOIN `location` p5 ON c.`LocationID` = p5.`ID`
  LEFT JOIN `priority` p6 ON c.`PriorityID` = p6.`ID`
  LEFT JOIN `companyproject` p7 ON c.`ProjectID` = p7.`ID`
  LEFT JOIN `sampleorder` p8 ON c.`ReferenceSOID` = p8.`ID`
  LEFT JOIN `sampleorderby` p9 ON c.`SampleOrderByID` = p9.`ID`
  LEFT JOIN `sampleorderfeedbackstatus` p10 ON c.`SampleOrderFeedbackStatusID` = p10.`ID`
  LEFT JOIN `sampleorderstatus` p11 ON c.`SampleOrderStatusID` = p11.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DeliveryID` = IF((c.`DeliveryID` IS NOT NULL AND (c.`DeliveryID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DeliveryID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`IndustryID` = IF((c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p4.`ID` IS NULL)), NULL, c.`IndustryID`),
       c.`LocationID` = IF((c.`LocationID` IS NOT NULL AND (c.`LocationID` = 0 OR p5.`ID` IS NULL)), NULL, c.`LocationID`),
       c.`PriorityID` = IF((c.`PriorityID` IS NOT NULL AND (c.`PriorityID` = 0 OR p6.`ID` IS NULL)), NULL, c.`PriorityID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p7.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`ReferenceSOID` = IF((c.`ReferenceSOID` IS NOT NULL AND (c.`ReferenceSOID` = 0 OR p8.`ID` IS NULL)), NULL, c.`ReferenceSOID`),
       c.`SampleOrderByID` = IF((c.`SampleOrderByID` IS NOT NULL AND (c.`SampleOrderByID` = 0 OR p9.`ID` IS NULL)), NULL, c.`SampleOrderByID`),
       c.`SampleOrderFeedbackStatusID` = IF((c.`SampleOrderFeedbackStatusID` IS NOT NULL AND (c.`SampleOrderFeedbackStatusID` = 0 OR p10.`ID` IS NULL)), NULL, c.`SampleOrderFeedbackStatusID`),
       c.`SampleOrderStatusID` = IF((c.`SampleOrderStatusID` IS NOT NULL AND (c.`SampleOrderStatusID` = 0 OR p11.`ID` IS NULL)), NULL, c.`SampleOrderStatusID`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DeliveryID` IS NOT NULL AND (c.`DeliveryID` = 0 OR p2.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p3.`ID` IS NULL))
    OR (c.`IndustryID` IS NOT NULL AND (c.`IndustryID` = 0 OR p4.`ID` IS NULL))
    OR (c.`LocationID` IS NOT NULL AND (c.`LocationID` = 0 OR p5.`ID` IS NULL))
    OR (c.`PriorityID` IS NOT NULL AND (c.`PriorityID` = 0 OR p6.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p7.`ID` IS NULL))
    OR (c.`ReferenceSOID` IS NOT NULL AND (c.`ReferenceSOID` = 0 OR p8.`ID` IS NULL))
    OR (c.`SampleOrderByID` IS NOT NULL AND (c.`SampleOrderByID` = 0 OR p9.`ID` IS NULL))
    OR (c.`SampleOrderFeedbackStatusID` IS NOT NULL AND (c.`SampleOrderFeedbackStatusID` = 0 OR p10.`ID` IS NULL))
    OR (c.`SampleOrderStatusID` IS NOT NULL AND (c.`SampleOrderStatusID` = 0 OR p11.`ID` IS NULL));
UPDATE `sampleorder` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDSales` = p1.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p1.`ID` IS NULL));
UPDATE `sampleorderassignment` c
  LEFT JOIN `sampleorder` p0 ON c.`SampleOrderID` = p0.`ID`
  LEFT JOIN `sampleorderstatus` p1 ON c.`SampleOrderStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`SampleOrderID` = IF((c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SampleOrderID`),
       c.`SampleOrderStatusID` = IF((c.`SampleOrderStatusID` IS NOT NULL AND (c.`SampleOrderStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SampleOrderStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SampleOrderStatusID` IS NOT NULL AND (c.`SampleOrderStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `sampleorderdetail` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `baranglists` p2 ON c.`BarangListID` = p2.`ID`
  LEFT JOIN `baranglists` p3 ON c.`BarangListIDRequest` = p3.`ID`
  LEFT JOIN `companyprojectdetailcc` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `sampleorderdetailstatus` p5 ON c.`SampleOrderDetailStatusID` = p5.`ID`
  LEFT JOIN `sampleorder` p6 ON c.`SampleOrderID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanID` = p7.`ID`
  LEFT JOIN `suratjalandetails` p8 ON c.`SuratJalanDetailID` = p8.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`BarangListID` = IF((c.`BarangListID` IS NOT NULL AND (c.`BarangListID` = 0 OR p2.`ID` IS NULL)), NULL, c.`BarangListID`),
       c.`BarangListIDRequest` = IF((c.`BarangListIDRequest` IS NOT NULL AND (c.`BarangListIDRequest` = 0 OR p3.`ID` IS NULL)), NULL, c.`BarangListIDRequest`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p4.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`SampleOrderDetailStatusID` = IF((c.`SampleOrderDetailStatusID` IS NOT NULL AND (c.`SampleOrderDetailStatusID` = 0 OR p5.`ID` IS NULL)), NULL, c.`SampleOrderDetailStatusID`),
       c.`SampleOrderID` = IF((c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p6.`ID` IS NULL)), NULL, c.`SampleOrderID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p7.`ID` IS NULL)), NULL, c.`SatuanID`),
       c.`SuratJalanDetailID` = IF((c.`SuratJalanDetailID` IS NOT NULL AND (c.`SuratJalanDetailID` = 0 OR p8.`ID` IS NULL)), NULL, c.`SuratJalanDetailID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`BarangListID` IS NOT NULL AND (c.`BarangListID` = 0 OR p2.`ID` IS NULL))
    OR (c.`BarangListIDRequest` IS NOT NULL AND (c.`BarangListIDRequest` = 0 OR p3.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p4.`ID` IS NULL))
    OR (c.`SampleOrderDetailStatusID` IS NOT NULL AND (c.`SampleOrderDetailStatusID` = 0 OR p5.`ID` IS NULL))
    OR (c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p6.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p7.`ID` IS NULL))
    OR (c.`SuratJalanDetailID` IS NOT NULL AND (c.`SuratJalanDetailID` = 0 OR p8.`ID` IS NULL));
UPDATE `sampleorderdetailassignment` c
  LEFT JOIN `sampleorderdetail` p0 ON c.`SampleOrderDetailID` = p0.`ID`
  LEFT JOIN `sampleorderdetailstatus` p1 ON c.`SampleOrderDetailStatusID` = p1.`ID`
  LEFT JOIN `sampleorder` p2 ON c.`SampleOrderID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`SampleOrderDetailID` = IF((c.`SampleOrderDetailID` IS NOT NULL AND (c.`SampleOrderDetailID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SampleOrderDetailID`),
       c.`SampleOrderDetailStatusID` = IF((c.`SampleOrderDetailStatusID` IS NOT NULL AND (c.`SampleOrderDetailStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SampleOrderDetailStatusID`),
       c.`SampleOrderID` = IF((c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p2.`ID` IS NULL)), NULL, c.`SampleOrderID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`SampleOrderDetailID` IS NOT NULL AND (c.`SampleOrderDetailID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SampleOrderDetailStatusID` IS NOT NULL AND (c.`SampleOrderDetailStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `sampleorderlink` c
  LEFT JOIN `sampleorder` p0 ON c.`SampleOrderID` = p0.`ID`
   SET
       c.`SampleOrderID` = IF((c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SampleOrderID`)
 WHERE  (c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p0.`ID` IS NULL));
UPDATE `samplerequestimport` c
  LEFT JOIN `delivery` p0 ON c.`DeliveryID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `samplerequestimport` p2 ON c.`ReferenceSRID` = p2.`ID`
  LEFT JOIN `samplerequestimportfrom` p3 ON c.`RequestFromID` = p3.`ID`
  LEFT JOIN `samplerequeststatus` p4 ON c.`SampleRequestStatusID` = p4.`ID`
  LEFT JOIN `urgency` p5 ON c.`UrgencyID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
   SET
       c.`DeliveryID` = IF((c.`DeliveryID` IS NOT NULL AND (c.`DeliveryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`DeliveryID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ReferenceSRID` = IF((c.`ReferenceSRID` IS NOT NULL AND (c.`ReferenceSRID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ReferenceSRID`),
       c.`RequestFromID` = IF((c.`RequestFromID` IS NOT NULL AND (c.`RequestFromID` = 0 OR p3.`ID` IS NULL)), NULL, c.`RequestFromID`),
       c.`SampleRequestStatusID` = IF((c.`SampleRequestStatusID` IS NOT NULL AND (c.`SampleRequestStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SampleRequestStatusID`),
       c.`UrgencyID` = IF((c.`UrgencyID` IS NOT NULL AND (c.`UrgencyID` = 0 OR p5.`ID` IS NULL)), NULL, c.`UrgencyID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDInput`)
 WHERE  (c.`DeliveryID` IS NOT NULL AND (c.`DeliveryID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ReferenceSRID` IS NOT NULL AND (c.`ReferenceSRID` = 0 OR p2.`ID` IS NULL))
    OR (c.`RequestFromID` IS NOT NULL AND (c.`RequestFromID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SampleRequestStatusID` IS NOT NULL AND (c.`SampleRequestStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UrgencyID` IS NOT NULL AND (c.`UrgencyID` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p6.`ID` IS NULL));
UPDATE `samplerequestimportassignment` c
  LEFT JOIN `samplerequestimport` p0 ON c.`SampleRequestImportID` = p0.`ID`
  LEFT JOIN `samplerequeststatus` p1 ON c.`SampleRequestStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`SampleRequestImportID` = IF((c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SampleRequestImportID`),
       c.`SampleRequestStatusID` = IF((c.`SampleRequestStatusID` IS NOT NULL AND (c.`SampleRequestStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SampleRequestStatusID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SampleRequestStatusID` IS NOT NULL AND (c.`SampleRequestStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `samplerequestimportdetail` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `baranglists` p1 ON c.`BaranglistID` = p1.`ID`
  LEFT JOIN `samplerequestimportgoodsreceipt` p2 ON c.`GoodReceiptDetailID` = p2.`ID`
  LEFT JOIN `company` p3 ON c.`ReqCompanyID` = p3.`ID`
  LEFT JOIN `samplerequeststatus` p4 ON c.`SampleRequestDetailStatusID` = p4.`ID`
  LEFT JOIN `samplerequestimport` p5 ON c.`SampleRequestImportID` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`SatuanID` = p6.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`BaranglistID` = IF((c.`BaranglistID` IS NOT NULL AND (c.`BaranglistID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BaranglistID`),
       c.`GoodReceiptDetailID` = IF((c.`GoodReceiptDetailID` IS NOT NULL AND (c.`GoodReceiptDetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`GoodReceiptDetailID`),
       c.`ReqCompanyID` = IF((c.`ReqCompanyID` IS NOT NULL AND (c.`ReqCompanyID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ReqCompanyID`),
       c.`SampleRequestDetailStatusID` = IF((c.`SampleRequestDetailStatusID` IS NOT NULL AND (c.`SampleRequestDetailStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SampleRequestDetailStatusID`),
       c.`SampleRequestImportID` = IF((c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p5.`ID` IS NULL)), NULL, c.`SampleRequestImportID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p6.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BaranglistID` IS NOT NULL AND (c.`BaranglistID` = 0 OR p1.`ID` IS NULL))
    OR (c.`GoodReceiptDetailID` IS NOT NULL AND (c.`GoodReceiptDetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ReqCompanyID` IS NOT NULL AND (c.`ReqCompanyID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SampleRequestDetailStatusID` IS NOT NULL AND (c.`SampleRequestDetailStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p5.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p6.`ID` IS NULL));
UPDATE `samplerequestimportdetailassignment` c
  LEFT JOIN `samplerequestimportdetail` p0 ON c.`SampleRequestDetailID` = p0.`ID`
  LEFT JOIN `samplerequeststatus` p1 ON c.`SampleRequestDetailStatusID` = p1.`ID`
  LEFT JOIN `samplerequestimport` p2 ON c.`SampleRequestImportID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
   SET
       c.`SampleRequestDetailID` = IF((c.`SampleRequestDetailID` IS NOT NULL AND (c.`SampleRequestDetailID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SampleRequestDetailID`),
       c.`SampleRequestDetailStatusID` = IF((c.`SampleRequestDetailStatusID` IS NOT NULL AND (c.`SampleRequestDetailStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SampleRequestDetailStatusID`),
       c.`SampleRequestImportID` = IF((c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p2.`ID` IS NULL)), NULL, c.`SampleRequestImportID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`SampleRequestDetailID` IS NOT NULL AND (c.`SampleRequestDetailID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SampleRequestDetailStatusID` IS NOT NULL AND (c.`SampleRequestDetailStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p2.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p3.`ID` IS NULL));
UPDATE `samplerequestimportgoodsreceipt` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `baranglists` p1 ON c.`BarangListsID` = p1.`ID`
  LEFT JOIN `samplerequestimportdetail` p2 ON c.`SampleRequestImportDetailID` = p2.`ID`
  LEFT JOIN `samplerequestimport` p3 ON c.`SampleRequestImportID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`SatuanID` = p4.`ID`
   SET
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`BarangListsID` = IF((c.`BarangListsID` IS NOT NULL AND (c.`BarangListsID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangListsID`),
       c.`SampleRequestImportDetailID` = IF((c.`SampleRequestImportDetailID` IS NOT NULL AND (c.`SampleRequestImportDetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`SampleRequestImportDetailID`),
       c.`SampleRequestImportID` = IF((c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p3.`ID` IS NULL)), NULL, c.`SampleRequestImportID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SatuanID`)
 WHERE  (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangListsID` IS NOT NULL AND (c.`BarangListsID` = 0 OR p1.`ID` IS NULL))
    OR (c.`SampleRequestImportDetailID` IS NOT NULL AND (c.`SampleRequestImportDetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`SampleRequestImportID` IS NOT NULL AND (c.`SampleRequestImportID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p4.`ID` IS NULL));
UPDATE `specialreference` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL));
UPDATE `specialreferencehistory` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `specialreference` p1 ON c.`SpecialReferenceID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
   SET
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`SpecialReferenceID` = IF((c.`SpecialReferenceID` IS NOT NULL AND (c.`SpecialReferenceID` = 0 OR p1.`ID` IS NULL)), NULL, c.`SpecialReferenceID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p0.`ID` IS NULL))
    OR (c.`SpecialReferenceID` IS NOT NULL AND (c.`SpecialReferenceID` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p2.`ID` IS NULL));
UPDATE `stockopname` c
  LEFT JOIN `packing` p0 ON c.`PackagingID` = p0.`ID`
  LEFT JOIN `stockopname_principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `stockopname_product` p2 ON c.`ProductID` = p2.`ID`
  LEFT JOIN `stockopnameby` p3 ON c.`StockOpnameBy` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`UOMID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `warehouse` p6 ON c.`WarehouseID` = p6.`ID`
   SET
       c.`PackagingID` = IF((c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PackagingID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`StockOpnameBy` = IF((c.`StockOpnameBy` IS NOT NULL AND (c.`StockOpnameBy` = 0 OR p3.`ID` IS NULL)), NULL, c.`StockOpnameBy`),
       c.`UOMID` = IF((c.`UOMID` IS NOT NULL AND (c.`UOMID` = 0 OR p4.`ID` IS NULL)), NULL, c.`UOMID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`WarehouseID` = IF((c.`WarehouseID` IS NOT NULL AND (c.`WarehouseID` = 0 OR p6.`ID` IS NULL)), NULL, c.`WarehouseID`)
 WHERE  (c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p2.`ID` IS NULL))
    OR (c.`StockOpnameBy` IS NOT NULL AND (c.`StockOpnameBy` = 0 OR p3.`ID` IS NULL))
    OR (c.`UOMID` IS NOT NULL AND (c.`UOMID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL))
    OR (c.`WarehouseID` IS NOT NULL AND (c.`WarehouseID` = 0 OR p6.`ID` IS NULL));
UPDATE `stockopname_product` c
  LEFT JOIN `stockopname_principal` p0 ON c.`PrincipalID` = p0.`ID`
  LEFT JOIN `satuan` p1 ON c.`UOMID` = p1.`ID`
   SET
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UOMID` = IF((c.`UOMID` IS NOT NULL AND (c.`UOMID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UOMID`)
 WHERE  (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UOMID` IS NOT NULL AND (c.`UOMID` = 0 OR p1.`ID` IS NULL));
UPDATE `stockopnamehistory` c
  LEFT JOIN `packing` p0 ON c.`PackagingID` = p0.`ID`
  LEFT JOIN `stockopname_principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `stockopname_product` p2 ON c.`ProductID` = p2.`ID`
  LEFT JOIN `stockopnameby` p3 ON c.`StockOpnameBy` = p3.`ID`
  LEFT JOIN `stockopname` p4 ON c.`StockOpnameID` = p4.`ID`
  LEFT JOIN `stockopnamestatus` p5 ON c.`StockOpnameStatusID` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`UOMID` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `warehouse` p8 ON c.`WarehouseID` = p8.`ID`
   SET
       c.`PackagingID` = IF((c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PackagingID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProductID` = IF((c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p2.`ID` IS NULL)), NULL, c.`ProductID`),
       c.`StockOpnameBy` = IF((c.`StockOpnameBy` IS NOT NULL AND (c.`StockOpnameBy` = 0 OR p3.`ID` IS NULL)), NULL, c.`StockOpnameBy`),
       c.`StockOpnameID` = IF((c.`StockOpnameID` IS NOT NULL AND (c.`StockOpnameID` = 0 OR p4.`ID` IS NULL)), NULL, c.`StockOpnameID`),
       c.`StockOpnameStatusID` = IF((c.`StockOpnameStatusID` IS NOT NULL AND (c.`StockOpnameStatusID` = 0 OR p5.`ID` IS NULL)), NULL, c.`StockOpnameStatusID`),
       c.`UOMID` = IF((c.`UOMID` IS NOT NULL AND (c.`UOMID` = 0 OR p6.`ID` IS NULL)), NULL, c.`UOMID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`WarehouseID` = IF((c.`WarehouseID` IS NOT NULL AND (c.`WarehouseID` = 0 OR p8.`ID` IS NULL)), NULL, c.`WarehouseID`)
 WHERE  (c.`PackagingID` IS NOT NULL AND (c.`PackagingID` = 0 OR p0.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p1.`ID` IS NULL))
    OR (c.`ProductID` IS NOT NULL AND (c.`ProductID` = 0 OR p2.`ID` IS NULL))
    OR (c.`StockOpnameBy` IS NOT NULL AND (c.`StockOpnameBy` = 0 OR p3.`ID` IS NULL))
    OR (c.`StockOpnameID` IS NOT NULL AND (c.`StockOpnameID` = 0 OR p4.`ID` IS NULL))
    OR (c.`StockOpnameStatusID` IS NOT NULL AND (c.`StockOpnameStatusID` = 0 OR p5.`ID` IS NULL))
    OR (c.`UOMID` IS NOT NULL AND (c.`UOMID` = 0 OR p6.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p7.`ID` IS NULL))
    OR (c.`WarehouseID` IS NOT NULL AND (c.`WarehouseID` = 0 OR p8.`ID` IS NULL));
UPDATE `successstory` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `groupdivision` p3 ON c.`GroupDivisionID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`GroupDivisionID` = IF((c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p3.`ID` IS NULL)), NULL, c.`GroupDivisionID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDSales`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p3.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p6.`ID` IS NULL));
UPDATE `successstoryassignment` c
  LEFT JOIN `successstory` p0 ON c.`SuccessStoryID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`SuccessStoryID` = IF((c.`SuccessStoryID` IS NOT NULL AND (c.`SuccessStoryID` = 0 OR p0.`ID` IS NULL)), NULL, c.`SuccessStoryID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`SuccessStoryID` IS NOT NULL AND (c.`SuccessStoryID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `suratjalan` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `delivery` p2 ON c.`DeliveryID` = p2.`ID`
  LEFT JOIN `location` p3 ON c.`LocationID` = p3.`ID`
  LEFT JOIN `sampleorder` p4 ON c.`SampleOrderID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDCreatorSJ` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDsales` = p6.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DeliveryID` = IF((c.`DeliveryID` IS NOT NULL AND (c.`DeliveryID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DeliveryID`),
       c.`LocationID` = IF((c.`LocationID` IS NOT NULL AND (c.`LocationID` = 0 OR p3.`ID` IS NULL)), NULL, c.`LocationID`),
       c.`SampleOrderID` = IF((c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SampleOrderID`),
       c.`UserIDCreatorSJ` = IF((c.`UserIDCreatorSJ` IS NOT NULL AND (c.`UserIDCreatorSJ` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDCreatorSJ`),
       c.`UserIDsales` = IF((c.`UserIDsales` IS NOT NULL AND (c.`UserIDsales` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDsales`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DeliveryID` IS NOT NULL AND (c.`DeliveryID` = 0 OR p2.`ID` IS NULL))
    OR (c.`LocationID` IS NOT NULL AND (c.`LocationID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDCreatorSJ` IS NOT NULL AND (c.`UserIDCreatorSJ` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDsales` IS NOT NULL AND (c.`UserIDsales` = 0 OR p6.`ID` IS NULL));
UPDATE `suratjalandetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `baranglists` p2 ON c.`BarangListID` = p2.`ID`
  LEFT JOIN `sampleorder` p3 ON c.`SampleOrderID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`SatuanID` = p4.`ID`
  LEFT JOIN `suratjalan` p5 ON c.`SuratJalanID` = p5.`ID`
   SET
       c.`ApplicationID` = IF((c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ApplicationID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`BarangListID` = IF((c.`BarangListID` IS NOT NULL AND (c.`BarangListID` = 0 OR p2.`ID` IS NULL)), NULL, c.`BarangListID`),
       c.`SampleOrderID` = IF((c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p3.`ID` IS NULL)), NULL, c.`SampleOrderID`),
       c.`SatuanID` = IF((c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p4.`ID` IS NULL)), NULL, c.`SatuanID`),
       c.`SuratJalanID` = IF((c.`SuratJalanID` IS NOT NULL AND (c.`SuratJalanID` = 0 OR p5.`ID` IS NULL)), NULL, c.`SuratJalanID`)
 WHERE  (c.`ApplicationID` IS NOT NULL AND (c.`ApplicationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`BarangListID` IS NOT NULL AND (c.`BarangListID` = 0 OR p2.`ID` IS NULL))
    OR (c.`SampleOrderID` IS NOT NULL AND (c.`SampleOrderID` = 0 OR p3.`ID` IS NULL))
    OR (c.`SatuanID` IS NOT NULL AND (c.`SatuanID` = 0 OR p4.`ID` IS NULL))
    OR (c.`SuratJalanID` IS NOT NULL AND (c.`SuratJalanID` = 0 OR p5.`ID` IS NULL));
UPDATE `userbusinesstravelbranch` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`BranchID` = IF((c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BranchID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `userdetails` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `department` p1 ON c.`DepartmentID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
   SET
       c.`BranchID` = IF((c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BranchID`),
       c.`DepartmentID` = IF((c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DepartmentID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`)
 WHERE  (c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL));
UPDATE `userdivision` c
  LEFT JOIN `division` p0 ON c.`DivisionID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p0.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `usereducation` c
  LEFT JOIN `education` p0 ON c.`EducationID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`EducationID` = IF((c.`EducationID` IS NOT NULL AND (c.`EducationID` = 0 OR p0.`ID` IS NULL)), NULL, c.`EducationID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`EducationID` IS NOT NULL AND (c.`EducationID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `userjob` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL));
UPDATE `userlabgroupdivision` c
  LEFT JOIN `groupdivision` p0 ON c.`GroupDivisionID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`GroupDivisionID` = IF((c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p0.`ID` IS NULL)), NULL, c.`GroupDivisionID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`GroupDivisionID` IS NOT NULL AND (c.`GroupDivisionID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `userprincipal` c
  LEFT JOIN `principal` p0 ON c.`PrincipalID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
   SET
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p1.`ID` IS NULL));
UPDATE `users` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `department` p1 ON c.`DepartmentID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`HeadID` = p2.`ID`
  LEFT JOIN `maritalstatus` p3 ON c.`MaritalStatusID` = p3.`ID`
  LEFT JOIN `role` p4 ON c.`RoleID` = p4.`ID`
   SET
       c.`BranchID` = IF((c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL)), NULL, c.`BranchID`),
       c.`DepartmentID` = IF((c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p1.`ID` IS NULL)), NULL, c.`DepartmentID`),
       c.`HeadID` = IF((c.`HeadID` IS NOT NULL AND (c.`HeadID` = 0 OR p2.`ID` IS NULL)), NULL, c.`HeadID`),
       c.`MaritalStatusID` = IF((c.`MaritalStatusID` IS NOT NULL AND (c.`MaritalStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`MaritalStatusID`),
       c.`RoleID` = IF((c.`RoleID` IS NOT NULL AND (c.`RoleID` = 0 OR p4.`ID` IS NULL)), NULL, c.`RoleID`)
 WHERE  (c.`BranchID` IS NOT NULL AND (c.`BranchID` = 0 OR p0.`ID` IS NULL))
    OR (c.`DepartmentID` IS NOT NULL AND (c.`DepartmentID` = 0 OR p1.`ID` IS NULL))
    OR (c.`HeadID` IS NOT NULL AND (c.`HeadID` = 0 OR p2.`ID` IS NULL))
    OR (c.`MaritalStatusID` IS NOT NULL AND (c.`MaritalStatusID` = 0 OR p3.`ID` IS NULL))
    OR (c.`RoleID` IS NOT NULL AND (c.`RoleID` = 0 OR p4.`ID` IS NULL));
UPDATE `usersperiode` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL));
UPDATE `userwarehouse` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `warehouse` p1 ON c.`WarehouseID` = p1.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`),
       c.`WarehouseID` = IF((c.`WarehouseID` IS NOT NULL AND (c.`WarehouseID` = 0 OR p1.`ID` IS NULL)), NULL, c.`WarehouseID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL))
    OR (c.`WarehouseID` IS NOT NULL AND (c.`WarehouseID` = 0 OR p1.`ID` IS NULL));
UPDATE `vehicle` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDOwner` = p1.`ID`
  LEFT JOIN `vehiclebrand` p2 ON c.`VehicleBrandID` = p2.`ID`
  LEFT JOIN `vehiclebrandtype` p3 ON c.`VehicleBrandTypeID` = p3.`ID`
  LEFT JOIN `vehiclecolor` p4 ON c.`VehicleColorID` = p4.`ID`
  LEFT JOIN `vehiclefueltype` p5 ON c.`VehicleFuelTypeID` = p5.`ID`
  LEFT JOIN `vehicletype` p6 ON c.`VehicleTypeID` = p6.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDOwner` = IF((c.`UserIDOwner` IS NOT NULL AND (c.`UserIDOwner` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserIDOwner`),
       c.`VehicleBrandID` = IF((c.`VehicleBrandID` IS NOT NULL AND (c.`VehicleBrandID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VehicleBrandID`),
       c.`VehicleBrandTypeID` = IF((c.`VehicleBrandTypeID` IS NOT NULL AND (c.`VehicleBrandTypeID` = 0 OR p3.`ID` IS NULL)), NULL, c.`VehicleBrandTypeID`),
       c.`VehicleColorID` = IF((c.`VehicleColorID` IS NOT NULL AND (c.`VehicleColorID` = 0 OR p4.`ID` IS NULL)), NULL, c.`VehicleColorID`),
       c.`VehicleFuelTypeID` = IF((c.`VehicleFuelTypeID` IS NOT NULL AND (c.`VehicleFuelTypeID` = 0 OR p5.`ID` IS NULL)), NULL, c.`VehicleFuelTypeID`),
       c.`VehicleTypeID` = IF((c.`VehicleTypeID` IS NOT NULL AND (c.`VehicleTypeID` = 0 OR p6.`ID` IS NULL)), NULL, c.`VehicleTypeID`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserIDOwner` IS NOT NULL AND (c.`UserIDOwner` = 0 OR p1.`ID` IS NULL))
    OR (c.`VehicleBrandID` IS NOT NULL AND (c.`VehicleBrandID` = 0 OR p2.`ID` IS NULL))
    OR (c.`VehicleBrandTypeID` IS NOT NULL AND (c.`VehicleBrandTypeID` = 0 OR p3.`ID` IS NULL))
    OR (c.`VehicleColorID` IS NOT NULL AND (c.`VehicleColorID` = 0 OR p4.`ID` IS NULL))
    OR (c.`VehicleFuelTypeID` IS NOT NULL AND (c.`VehicleFuelTypeID` = 0 OR p5.`ID` IS NULL))
    OR (c.`VehicleTypeID` IS NOT NULL AND (c.`VehicleTypeID` = 0 OR p6.`ID` IS NULL));
UPDATE `vehicleassignment` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDOwnerAfter` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDOwnerBefore` = p2.`ID`
  LEFT JOIN `vehiclebrand` p3 ON c.`VehicleBrandIDAfter` = p3.`ID`
  LEFT JOIN `vehiclebrand` p4 ON c.`VehicleBrandIDBefore` = p4.`ID`
  LEFT JOIN `vehiclebrandtype` p5 ON c.`VehicleBrandTypeIDAfter` = p5.`ID`
  LEFT JOIN `vehiclebrandtype` p6 ON c.`VehicleBrandTypeIDBefore` = p6.`ID`
  LEFT JOIN `vehiclecolor` p7 ON c.`VehicleColorIDAfter` = p7.`ID`
  LEFT JOIN `vehiclecolor` p8 ON c.`VehicleColorIDBefore` = p8.`ID`
  LEFT JOIN `vehiclefueltype` p9 ON c.`VehicleFuelTypeIDAfter` = p9.`ID`
  LEFT JOIN `vehiclefueltype` p10 ON c.`VehicleFuelTypeIDBefore` = p10.`ID`
  LEFT JOIN `vehicle` p11 ON c.`VehicleID` = p11.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDOwnerAfter` = IF((c.`UserIDOwnerAfter` IS NOT NULL AND (c.`UserIDOwnerAfter` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserIDOwnerAfter`),
       c.`UserIDOwnerBefore` = IF((c.`UserIDOwnerBefore` IS NOT NULL AND (c.`UserIDOwnerBefore` = 0 OR p2.`ID` IS NULL)), NULL, c.`UserIDOwnerBefore`),
       c.`VehicleBrandIDAfter` = IF((c.`VehicleBrandIDAfter` IS NOT NULL AND (c.`VehicleBrandIDAfter` = 0 OR p3.`ID` IS NULL)), NULL, c.`VehicleBrandIDAfter`),
       c.`VehicleBrandIDBefore` = IF((c.`VehicleBrandIDBefore` IS NOT NULL AND (c.`VehicleBrandIDBefore` = 0 OR p4.`ID` IS NULL)), NULL, c.`VehicleBrandIDBefore`),
       c.`VehicleBrandTypeIDAfter` = IF((c.`VehicleBrandTypeIDAfter` IS NOT NULL AND (c.`VehicleBrandTypeIDAfter` = 0 OR p5.`ID` IS NULL)), NULL, c.`VehicleBrandTypeIDAfter`),
       c.`VehicleBrandTypeIDBefore` = IF((c.`VehicleBrandTypeIDBefore` IS NOT NULL AND (c.`VehicleBrandTypeIDBefore` = 0 OR p6.`ID` IS NULL)), NULL, c.`VehicleBrandTypeIDBefore`),
       c.`VehicleColorIDAfter` = IF((c.`VehicleColorIDAfter` IS NOT NULL AND (c.`VehicleColorIDAfter` = 0 OR p7.`ID` IS NULL)), NULL, c.`VehicleColorIDAfter`),
       c.`VehicleColorIDBefore` = IF((c.`VehicleColorIDBefore` IS NOT NULL AND (c.`VehicleColorIDBefore` = 0 OR p8.`ID` IS NULL)), NULL, c.`VehicleColorIDBefore`),
       c.`VehicleFuelTypeIDAfter` = IF((c.`VehicleFuelTypeIDAfter` IS NOT NULL AND (c.`VehicleFuelTypeIDAfter` = 0 OR p9.`ID` IS NULL)), NULL, c.`VehicleFuelTypeIDAfter`),
       c.`VehicleFuelTypeIDBefore` = IF((c.`VehicleFuelTypeIDBefore` IS NOT NULL AND (c.`VehicleFuelTypeIDBefore` = 0 OR p10.`ID` IS NULL)), NULL, c.`VehicleFuelTypeIDBefore`),
       c.`VehicleID` = IF((c.`VehicleID` IS NOT NULL AND (c.`VehicleID` = 0 OR p11.`ID` IS NULL)), NULL, c.`VehicleID`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserIDOwnerAfter` IS NOT NULL AND (c.`UserIDOwnerAfter` = 0 OR p1.`ID` IS NULL))
    OR (c.`UserIDOwnerBefore` IS NOT NULL AND (c.`UserIDOwnerBefore` = 0 OR p2.`ID` IS NULL))
    OR (c.`VehicleBrandIDAfter` IS NOT NULL AND (c.`VehicleBrandIDAfter` = 0 OR p3.`ID` IS NULL))
    OR (c.`VehicleBrandIDBefore` IS NOT NULL AND (c.`VehicleBrandIDBefore` = 0 OR p4.`ID` IS NULL))
    OR (c.`VehicleBrandTypeIDAfter` IS NOT NULL AND (c.`VehicleBrandTypeIDAfter` = 0 OR p5.`ID` IS NULL))
    OR (c.`VehicleBrandTypeIDBefore` IS NOT NULL AND (c.`VehicleBrandTypeIDBefore` = 0 OR p6.`ID` IS NULL))
    OR (c.`VehicleColorIDAfter` IS NOT NULL AND (c.`VehicleColorIDAfter` = 0 OR p7.`ID` IS NULL))
    OR (c.`VehicleColorIDBefore` IS NOT NULL AND (c.`VehicleColorIDBefore` = 0 OR p8.`ID` IS NULL))
    OR (c.`VehicleFuelTypeIDAfter` IS NOT NULL AND (c.`VehicleFuelTypeIDAfter` = 0 OR p9.`ID` IS NULL))
    OR (c.`VehicleFuelTypeIDBefore` IS NOT NULL AND (c.`VehicleFuelTypeIDBefore` = 0 OR p10.`ID` IS NULL))
    OR (c.`VehicleID` IS NOT NULL AND (c.`VehicleID` = 0 OR p11.`ID` IS NULL));
UPDATE `vehicleassignment` c
  LEFT JOIN `vehiclestatus` p0 ON c.`VehicleStatusID` = p0.`ID`
  LEFT JOIN `vehicletype` p1 ON c.`VehicleTypeIDAfter` = p1.`ID`
  LEFT JOIN `vehicletype` p2 ON c.`VehicleTypeIDBefore` = p2.`ID`
   SET
       c.`VehicleStatusID` = IF((c.`VehicleStatusID` IS NOT NULL AND (c.`VehicleStatusID` = 0 OR p0.`ID` IS NULL)), NULL, c.`VehicleStatusID`),
       c.`VehicleTypeIDAfter` = IF((c.`VehicleTypeIDAfter` IS NOT NULL AND (c.`VehicleTypeIDAfter` = 0 OR p1.`ID` IS NULL)), NULL, c.`VehicleTypeIDAfter`),
       c.`VehicleTypeIDBefore` = IF((c.`VehicleTypeIDBefore` IS NOT NULL AND (c.`VehicleTypeIDBefore` = 0 OR p2.`ID` IS NULL)), NULL, c.`VehicleTypeIDBefore`)
 WHERE  (c.`VehicleStatusID` IS NOT NULL AND (c.`VehicleStatusID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VehicleTypeIDAfter` IS NOT NULL AND (c.`VehicleTypeIDAfter` = 0 OR p1.`ID` IS NULL))
    OR (c.`VehicleTypeIDBefore` IS NOT NULL AND (c.`VehicleTypeIDBefore` = 0 OR p2.`ID` IS NULL));
UPDATE `vehiclebrandtype` c
  LEFT JOIN `vehiclebrand` p0 ON c.`VehicleBrandID` = p0.`ID`
   SET
       c.`VehicleBrandID` = IF((c.`VehicleBrandID` IS NOT NULL AND (c.`VehicleBrandID` = 0 OR p0.`ID` IS NULL)), NULL, c.`VehicleBrandID`)
 WHERE  (c.`VehicleBrandID` IS NOT NULL AND (c.`VehicleBrandID` = 0 OR p0.`ID` IS NULL));
UPDATE `vehicleservicerequest` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDOwner` = p1.`ID`
  LEFT JOIN `vehicle` p2 ON c.`VehicleID` = p2.`ID`
  LEFT JOIN `vehicleservicerequeststatus` p3 ON c.`VehicleServiceRequestStatusID` = p3.`ID`
   SET
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDOwner` = IF((c.`UserIDOwner` IS NOT NULL AND (c.`UserIDOwner` = 0 OR p1.`ID` IS NULL)), NULL, c.`UserIDOwner`),
       c.`VehicleID` = IF((c.`VehicleID` IS NOT NULL AND (c.`VehicleID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VehicleID`),
       c.`VehicleServiceRequestStatusID` = IF((c.`VehicleServiceRequestStatusID` IS NOT NULL AND (c.`VehicleServiceRequestStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`VehicleServiceRequestStatusID`)
 WHERE  (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p0.`ID` IS NULL))
    OR (c.`UserIDOwner` IS NOT NULL AND (c.`UserIDOwner` = 0 OR p1.`ID` IS NULL))
    OR (c.`VehicleID` IS NOT NULL AND (c.`VehicleID` = 0 OR p2.`ID` IS NULL))
    OR (c.`VehicleServiceRequestStatusID` IS NOT NULL AND (c.`VehicleServiceRequestStatusID` = 0 OR p3.`ID` IS NULL));
UPDATE `vehicleservicerequestassignment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `vehicleservicerequest` p1 ON c.`VehicleServiceRequestID` = p1.`ID`
  LEFT JOIN `vehicleservicerequeststatus` p2 ON c.`VehicleServiceRequestStatusID` = p2.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`),
       c.`VehicleServiceRequestID` = IF((c.`VehicleServiceRequestID` IS NOT NULL AND (c.`VehicleServiceRequestID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VehicleServiceRequestID`),
       c.`VehicleServiceRequestStatusID` = IF((c.`VehicleServiceRequestStatusID` IS NOT NULL AND (c.`VehicleServiceRequestStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VehicleServiceRequestStatusID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VehicleServiceRequestID` IS NOT NULL AND (c.`VehicleServiceRequestID` = 0 OR p1.`ID` IS NULL))
    OR (c.`VehicleServiceRequestStatusID` IS NOT NULL AND (c.`VehicleServiceRequestStatusID` = 0 OR p2.`ID` IS NULL));
UPDATE `vehicleservicerequestdetails` c
  LEFT JOIN `vehicleservicerequeststatus` p0 ON c.`VehicleServiceRequestDetailStatus` = p0.`ID`
  LEFT JOIN `vehicleservicerequest` p1 ON c.`VehicleServiceRequestID` = p1.`ID`
  LEFT JOIN `vehicleservicetype` p2 ON c.`VehicleServiceTypeID` = p2.`ID`
   SET
       c.`VehicleServiceRequestDetailStatus` = IF((c.`VehicleServiceRequestDetailStatus` IS NOT NULL AND (c.`VehicleServiceRequestDetailStatus` = 0 OR p0.`ID` IS NULL)), NULL, c.`VehicleServiceRequestDetailStatus`),
       c.`VehicleServiceRequestID` = IF((c.`VehicleServiceRequestID` IS NOT NULL AND (c.`VehicleServiceRequestID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VehicleServiceRequestID`),
       c.`VehicleServiceTypeID` = IF((c.`VehicleServiceTypeID` IS NOT NULL AND (c.`VehicleServiceTypeID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VehicleServiceTypeID`)
 WHERE  (c.`VehicleServiceRequestDetailStatus` IS NOT NULL AND (c.`VehicleServiceRequestDetailStatus` = 0 OR p0.`ID` IS NULL))
    OR (c.`VehicleServiceRequestID` IS NOT NULL AND (c.`VehicleServiceRequestID` = 0 OR p1.`ID` IS NULL))
    OR (c.`VehicleServiceTypeID` IS NOT NULL AND (c.`VehicleServiceTypeID` = 0 OR p2.`ID` IS NULL));
UPDATE `vehicleservicerequestdetailsassigntment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `vehicleservicerequestdetails` p1 ON c.`VehicleServiceRequestDetailID` = p1.`ID`
  LEFT JOIN `vehicleservicerequest` p2 ON c.`VehicleServiceRequestID` = p2.`ID`
  LEFT JOIN `vehicleservicerequeststatus` p3 ON c.`VehicleServiceRequestStatusID` = p3.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`),
       c.`VehicleServiceRequestDetailID` = IF((c.`VehicleServiceRequestDetailID` IS NOT NULL AND (c.`VehicleServiceRequestDetailID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VehicleServiceRequestDetailID`),
       c.`VehicleServiceRequestID` = IF((c.`VehicleServiceRequestID` IS NOT NULL AND (c.`VehicleServiceRequestID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VehicleServiceRequestID`),
       c.`VehicleServiceRequestStatusID` = IF((c.`VehicleServiceRequestStatusID` IS NOT NULL AND (c.`VehicleServiceRequestStatusID` = 0 OR p3.`ID` IS NULL)), NULL, c.`VehicleServiceRequestStatusID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VehicleServiceRequestDetailID` IS NOT NULL AND (c.`VehicleServiceRequestDetailID` = 0 OR p1.`ID` IS NULL))
    OR (c.`VehicleServiceRequestID` IS NOT NULL AND (c.`VehicleServiceRequestID` = 0 OR p2.`ID` IS NULL))
    OR (c.`VehicleServiceRequestStatusID` IS NOT NULL AND (c.`VehicleServiceRequestStatusID` = 0 OR p3.`ID` IS NULL));
UPDATE `visitplan` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `companyproject` p3 ON c.`ProjectID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDInput` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDSales` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDVisitWith` = p6.`ID`
  LEFT JOIN `visitplanstatus` p7 ON c.`VisitPlanStatusID` = p7.`ID`
  LEFT JOIN `principalcp` p8 ON c.`VisitPrincipalCPID` = p8.`ID`
  LEFT JOIN `principal` p9 ON c.`VisitingPrincipalID` = p9.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`CompanyID` = IF((c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL)), NULL, c.`CompanyID`),
       c.`DivisionID` = IF((c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL)), NULL, c.`DivisionID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`UserIDInput` = IF((c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p4.`ID` IS NULL)), NULL, c.`UserIDInput`),
       c.`UserIDSales` = IF((c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p5.`ID` IS NULL)), NULL, c.`UserIDSales`),
       c.`UserIDVisitWith` = IF((c.`UserIDVisitWith` IS NOT NULL AND (c.`UserIDVisitWith` = 0 OR p6.`ID` IS NULL)), NULL, c.`UserIDVisitWith`),
       c.`VisitPlanStatusID` = IF((c.`VisitPlanStatusID` IS NOT NULL AND (c.`VisitPlanStatusID` = 0 OR p7.`ID` IS NULL)), NULL, c.`VisitPlanStatusID`),
       c.`VisitPrincipalCPID` = IF((c.`VisitPrincipalCPID` IS NOT NULL AND (c.`VisitPrincipalCPID` = 0 OR p8.`ID` IS NULL)), NULL, c.`VisitPrincipalCPID`),
       c.`VisitingPrincipalID` = IF((c.`VisitingPrincipalID` IS NOT NULL AND (c.`VisitingPrincipalID` = 0 OR p9.`ID` IS NULL)), NULL, c.`VisitingPrincipalID`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`CompanyID` IS NOT NULL AND (c.`CompanyID` = 0 OR p1.`ID` IS NULL))
    OR (c.`DivisionID` IS NOT NULL AND (c.`DivisionID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p3.`ID` IS NULL))
    OR (c.`UserIDInput` IS NOT NULL AND (c.`UserIDInput` = 0 OR p4.`ID` IS NULL))
    OR (c.`UserIDSales` IS NOT NULL AND (c.`UserIDSales` = 0 OR p5.`ID` IS NULL))
    OR (c.`UserIDVisitWith` IS NOT NULL AND (c.`UserIDVisitWith` = 0 OR p6.`ID` IS NULL))
    OR (c.`VisitPlanStatusID` IS NOT NULL AND (c.`VisitPlanStatusID` = 0 OR p7.`ID` IS NULL))
    OR (c.`VisitPrincipalCPID` IS NOT NULL AND (c.`VisitPrincipalCPID` = 0 OR p8.`ID` IS NULL))
    OR (c.`VisitingPrincipalID` IS NOT NULL AND (c.`VisitingPrincipalID` = 0 OR p9.`ID` IS NULL));
UPDATE `visitplanassignment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `visitplan` p1 ON c.`VisitPlanID` = p1.`ID`
  LEFT JOIN `visitplanstatus` p2 ON c.`VisitPlanStatusID` = p2.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`),
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VisitPlanID`),
       c.`VisitPlanStatusID` = IF((c.`VisitPlanStatusID` IS NOT NULL AND (c.`VisitPlanStatusID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VisitPlanStatusID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p1.`ID` IS NULL))
    OR (c.`VisitPlanStatusID` IS NOT NULL AND (c.`VisitPlanStatusID` = 0 OR p2.`ID` IS NULL));
UPDATE `visitplancompanycpdetail` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `visitplan` p1 ON c.`VisitPlanID` = p1.`ID`
   SET
       c.`CompanyCPID` = IF((c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL)), NULL, c.`CompanyCPID`),
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VisitPlanID`)
 WHERE  (c.`CompanyCPID` IS NOT NULL AND (c.`CompanyCPID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p1.`ID` IS NULL));
UPDATE `visitplandetail` c
  LEFT JOIN `action` p0 ON c.`ActionID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
  LEFT JOIN `companyprojectdetailcc` p3 ON c.`ProjectID` = p3.`ID`
  LEFT JOIN `visitplanstatus` p4 ON c.`VisitActionStatusID` = p4.`ID`
  LEFT JOIN `visitplan` p5 ON c.`VisitPlanID` = p5.`ID`
   SET
       c.`ActionID` = IF((c.`ActionID` IS NOT NULL AND (c.`ActionID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ActionID`),
       c.`BarangID` = IF((c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL)), NULL, c.`BarangID`),
       c.`PrincipalID` = IF((c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL)), NULL, c.`PrincipalID`),
       c.`ProjectID` = IF((c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p3.`ID` IS NULL)), NULL, c.`ProjectID`),
       c.`VisitActionStatusID` = IF((c.`VisitActionStatusID` IS NOT NULL AND (c.`VisitActionStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`VisitActionStatusID`),
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p5.`ID` IS NULL)), NULL, c.`VisitPlanID`)
 WHERE  (c.`ActionID` IS NOT NULL AND (c.`ActionID` = 0 OR p0.`ID` IS NULL))
    OR (c.`BarangID` IS NOT NULL AND (c.`BarangID` = 0 OR p1.`ID` IS NULL))
    OR (c.`PrincipalID` IS NOT NULL AND (c.`PrincipalID` = 0 OR p2.`ID` IS NULL))
    OR (c.`ProjectID` IS NOT NULL AND (c.`ProjectID` = 0 OR p3.`ID` IS NULL))
    OR (c.`VisitActionStatusID` IS NOT NULL AND (c.`VisitActionStatusID` = 0 OR p4.`ID` IS NULL))
    OR (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p5.`ID` IS NULL));
UPDATE `visitplandetailassignment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `visitplanstatus` p1 ON c.`VisitActionStatusID` = p1.`ID`
  LEFT JOIN `visitplandetail` p2 ON c.`VisitPlanDetailID` = p2.`ID`
  LEFT JOIN `visitplan` p3 ON c.`VisitPlanID` = p3.`ID`
  LEFT JOIN `visitplanstatus` p4 ON c.`VisitPlanStatusID` = p4.`ID`
   SET
       c.`UserID` = IF((c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserID`),
       c.`VisitActionStatusID` = IF((c.`VisitActionStatusID` IS NOT NULL AND (c.`VisitActionStatusID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VisitActionStatusID`),
       c.`VisitPlanDetailID` = IF((c.`VisitPlanDetailID` IS NOT NULL AND (c.`VisitPlanDetailID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VisitPlanDetailID`),
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p3.`ID` IS NULL)), NULL, c.`VisitPlanID`),
       c.`VisitPlanStatusID` = IF((c.`VisitPlanStatusID` IS NOT NULL AND (c.`VisitPlanStatusID` = 0 OR p4.`ID` IS NULL)), NULL, c.`VisitPlanStatusID`)
 WHERE  (c.`UserID` IS NOT NULL AND (c.`UserID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VisitActionStatusID` IS NOT NULL AND (c.`VisitActionStatusID` = 0 OR p1.`ID` IS NULL))
    OR (c.`VisitPlanDetailID` IS NOT NULL AND (c.`VisitPlanDetailID` = 0 OR p2.`ID` IS NULL))
    OR (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p3.`ID` IS NULL))
    OR (c.`VisitPlanStatusID` IS NOT NULL AND (c.`VisitPlanStatusID` = 0 OR p4.`ID` IS NULL));
UPDATE `visitplanfrienddetail` c
  LEFT JOIN `users` p0 ON c.`UserIDVisitWith` = p0.`ID`
  LEFT JOIN `visitplan` p1 ON c.`VisitPlanID` = p1.`ID`
   SET
       c.`UserIDVisitWith` = IF((c.`UserIDVisitWith` IS NOT NULL AND (c.`UserIDVisitWith` = 0 OR p0.`ID` IS NULL)), NULL, c.`UserIDVisitWith`),
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VisitPlanID`)
 WHERE  (c.`UserIDVisitWith` IS NOT NULL AND (c.`UserIDVisitWith` = 0 OR p0.`ID` IS NULL))
    OR (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p1.`ID` IS NULL));
UPDATE `visitplanlink` c
  LEFT JOIN `visitplan` p0 ON c.`VisitPlanID` = p0.`ID`
   SET
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p0.`ID` IS NULL)), NULL, c.`VisitPlanID`)
 WHERE  (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p0.`ID` IS NULL));
UPDATE `visitplanprincipalvisitdetail` c
  LEFT JOIN `visitplan` p0 ON c.`VisitPlanID` = p0.`ID`
  LEFT JOIN `principalcp` p1 ON c.`VisitingPrincipalCPID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`VisitingPrincipalID` = p2.`ID`
   SET
       c.`VisitPlanID` = IF((c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p0.`ID` IS NULL)), NULL, c.`VisitPlanID`),
       c.`VisitingPrincipalCPID` = IF((c.`VisitingPrincipalCPID` IS NOT NULL AND (c.`VisitingPrincipalCPID` = 0 OR p1.`ID` IS NULL)), NULL, c.`VisitingPrincipalCPID`),
       c.`VisitingPrincipalID` = IF((c.`VisitingPrincipalID` IS NOT NULL AND (c.`VisitingPrincipalID` = 0 OR p2.`ID` IS NULL)), NULL, c.`VisitingPrincipalID`)
 WHERE  (c.`VisitPlanID` IS NOT NULL AND (c.`VisitPlanID` = 0 OR p0.`ID` IS NULL))
    OR (c.`VisitingPrincipalCPID` IS NOT NULL AND (c.`VisitingPrincipalCPID` = 0 OR p1.`ID` IS NULL))
    OR (c.`VisitingPrincipalID` IS NOT NULL AND (c.`VisitingPrincipalID` = 0 OR p2.`ID` IS NULL));
UPDATE `warehouse` c
  LEFT JOIN `warehouse` p0 ON c.`ParentID` = p0.`ID`
   SET
       c.`ParentID` = IF((c.`ParentID` IS NOT NULL AND (c.`ParentID` = 0 OR p0.`ID` IS NULL)), NULL, c.`ParentID`)
 WHERE  (c.`ParentID` IS NOT NULL AND (c.`ParentID` = 0 OR p0.`ID` IS NULL));

COMMIT;

-- ---------------------------------------------------------------------
-- SECTION 7b - ORPHAN ASSERTION  (NEW -- this is what pays for section 8 being fast)
--
-- The original created the foreign keys with FOREIGN_KEY_CHECKS ON so that any row the
-- cleanup missed would abort the run. That cost 154 full table copies, because InnoDB
-- cannot add a validated foreign key in place. This section buys the SAME protection with
-- one indexed pass per table, and section 8 then adds the constraints as metadata only.
--
-- Coverage: all 651 distinct (child, column, parent) relationships behind the 659
-- constraints -- 8 of which are second constraints on a column already listed. That is
-- WIDER than the cleanup it verifies: section 6 cleans 644 of the 659, and the other 15
-- (14 on the empty tables section 2 creates, 1 on the DEFAULT NULL column section 3b adds)
-- were previously validated only as a side effect of FOREIGN_KEY_CHECKS.
--
-- The indexes section A created are what make this cheap.
--
-- ⚠ IF THIS ABORTS: a row survived the cleanup. That is the same stop-and-look event the
--   original would have hit as ERROR 1452 inside section 8 -- but here NOTHING has been
--   created yet, and the count below tells you how many relationships are affected instead
--   of dying at whichever table came first alphabetically.
-- ---------------------------------------------------------------------
SET @orphans = 0;
SELECT COUNT(*) INTO @n FROM `application` c
  LEFT JOIN `division` p0 ON c.`DivisionID` = p0.`ID`
  LEFT JOIN `groupdivision` p1 ON c.`GroupDivisionID` = p1.`ID`
 WHERE  (c.`DivisionID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`GroupDivisionID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `bank` c
  LEFT JOIN `quotationpricedesc` p0 ON c.`QuotationPriceDescID` = p0.`ID`
 WHERE  (c.`QuotationPriceDescID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `bankdivision` c
  LEFT JOIN `bank` p0 ON c.`BankID` = p0.`ID`
  LEFT JOIN `division` p1 ON c.`DivisionID` = p1.`ID`
 WHERE  (c.`BankID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `barang` c
  LEFT JOIN `category` p0 ON c.`CategoryID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `satuan` p2 ON c.`SatuanID` = p2.`ID`
  LEFT JOIN `type` p3 ON c.`TypeID` = p3.`ID`
 WHERE  (c.`CategoryID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`TypeID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `baranglist` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `barangliststatus` p1 ON c.`BarangListStatusID` = p1.`ID`
  LEFT JOIN `sampleorderdetail` p2 ON c.`SampleOrderDetailID` = p2.`ID`
  LEFT JOIN `satuan` p3 ON c.`SatuanID` = p3.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangListStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`SampleOrderDetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `baranglists` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `satuan` p1 ON c.`SatuanID` = p1.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `barangstockmin` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `satuan` p1 ON c.`SatuanID` = p1.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `budgetandtarget` c
  LEFT JOIN `budgetandtargetperiode` p0 ON c.`BudgetAndTargetPeriodeID` = p0.`ID`
  LEFT JOIN `budgetandtargetstatus` p1 ON c.`BudgetAndTargetStatusID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
 WHERE  (c.`BudgetAndTargetPeriodeID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BudgetAndTargetStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `budgetandtargetachievements` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `budgetandtargetperiode` p1 ON c.`BudgetAndTargetPeriodeID` = p1.`ID`
  LEFT JOIN `budgetandtargetstatus` p2 ON c.`BudgetAndTargetStatusID` = p2.`ID`
  LEFT JOIN `company` p3 ON c.`CompanyID` = p3.`ID`
  LEFT JOIN `division` p4 ON c.`DivisionID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BudgetAndTargetPeriodeID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`BudgetAndTargetStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `budgetandtargetassignment` c
  LEFT JOIN `budgetandtarget` p0 ON c.`BudgetAndTargetID` = p0.`ID`
  LEFT JOIN `budgetandtargetstatus` p1 ON c.`BudgetAndTargetStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`BudgetAndTargetID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BudgetAndTargetStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `budgetandtargetreal` c
  LEFT JOIN `budgetandtargetperiode` p0 ON c.`BudgetAndTargetPeriodeID` = p0.`ID`
  LEFT JOIN `budgetandtargetstatus` p1 ON c.`BudgetAndTargetStatusID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
 WHERE  (c.`BudgetAndTargetPeriodeID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BudgetAndTargetStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `comissionpercentage` c
  LEFT JOIN `principal` p0 ON c.`PrincipalID` = p0.`ID`
 WHERE  (c.`PrincipalID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `company` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `companycategory` p1 ON c.`CompanyCategoryID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDSales` = p4.`ID`
 WHERE  (c.`BranchID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyCategoryID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyaccessothers` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companycategory` c
  LEFT JOIN `groupdivision` p0 ON c.`GroupDivID` = p0.`ID`
 WHERE  (c.`GroupDivID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companycategorylist` c
  LEFT JOIN `companycategory` p0 ON c.`CompanyCategoryID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
 WHERE  (c.`CompanyCategoryID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companycp` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
 WHERE  (c.`AddressType` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companycpassignment` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `companycp` p1 ON c.`CompanyCPID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UsersID` = p3.`ID`
 WHERE  (c.`AddressType` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyCPID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UsersID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyhistory` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDSales` = p4.`ID`
 WHERE  (c.`BranchID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyindustry` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `industry` p1 ON c.`IndustryID` = p1.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproduct` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`CCBarangID` = p1.`ID`
  LEFT JOIN `satuan` p2 ON c.`CCPriceSatuanID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`CCPrincipalID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`CCVolumeSatuanID` = p4.`ID`
  LEFT JOIN `company` p5 ON c.`CompanyID` = p5.`ID`
  LEFT JOIN `barang` p6 ON c.`CompetitorBarangID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`CompetitorPriceSatuanID` = p7.`ID`
  LEFT JOIN `principal` p8 ON c.`CompetitorPrincipalID` = p8.`ID`
  LEFT JOIN `satuan` p9 ON c.`CompetitorVolumeSatuanID` = p9.`ID`
  LEFT JOIN `division` p10 ON c.`DivisionID` = p10.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CCBarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CCPriceSatuanID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`CCPrincipalID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`CCVolumeSatuanID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`CompetitorBarangID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`CompetitorPriceSatuanID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`CompetitorPrincipalID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`CompetitorVolumeSatuanID` IS NOT NULL AND p9.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p10.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproductapplication` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `application` p1 ON c.`ProductApplicationID` = p1.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ProductApplicationID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproductassignment` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`CCBarangID` = p1.`ID`
  LEFT JOIN `satuan` p2 ON c.`CCPriceSatuanID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`CCPrincipalID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`CCVolumeSatuanID` = p4.`ID`
  LEFT JOIN `company` p5 ON c.`CompanyID` = p5.`ID`
  LEFT JOIN `companyproduct` p6 ON c.`CompanyProductID` = p6.`ID`
  LEFT JOIN `barang` p7 ON c.`CompetitorBarangID` = p7.`ID`
  LEFT JOIN `satuan` p8 ON c.`CompetitorPriceSatuanID` = p8.`ID`
  LEFT JOIN `principal` p9 ON c.`CompetitorPrincipalID` = p9.`ID`
  LEFT JOIN `satuan` p10 ON c.`CompetitorVolumeSatuanID` = p10.`ID`
  LEFT JOIN `division` p11 ON c.`DivisionID` = p11.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CCBarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CCPriceSatuanID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`CCPrincipalID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`CCVolumeSatuanID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`CompanyProductID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`CompetitorBarangID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`CompetitorPriceSatuanID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`CompetitorPrincipalID` IS NOT NULL AND p9.`ID` IS NULL)
    OR (c.`CompetitorVolumeSatuanID` IS NOT NULL AND p10.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p11.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproductassignment` c
  LEFT JOIN `users` p0 ON c.`UsersID` = p0.`ID`
 WHERE  (c.`UsersID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproductcategory` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `category` p1 ON c.`ProductCategoryID` = p1.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ProductCategoryID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproduction` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `satuan` p3 ON c.`VolumeSatuanID` = p3.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`VolumeSatuanID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproductionassignment` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `companyproduction` p2 ON c.`CompanyProductionID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UsersID` = p4.`ID`
  LEFT JOIN `satuan` p5 ON c.`VolumeSatuanID` = p5.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyProductionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UsersID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`VolumeSatuanID` IS NOT NULL AND p5.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyproject` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCP` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `companyproject` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `companyprojectpriority` p5 ON c.`ProjectPriority` = p5.`ID`
  LEFT JOIN `companyprojectstatus` p6 ON c.`ProjectStatusID` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDSales` = p8.`ID`
 WHERE  (c.`CompanyCP` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`ProjectPriority` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`ProjectStatusID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectassignment` c
  LEFT JOIN `companyprojectdetailcc` p0 ON c.`CompanyProjectDetailCCID` = p0.`ID`
  LEFT JOIN `companyprojectdetails` p1 ON c.`CompanyProjectDetailID` = p1.`ID`
  LEFT JOIN `companyproject` p2 ON c.`CompanyProjectID` = p2.`ID`
  LEFT JOIN `companyprojectstatus` p3 ON c.`ProjectStatusID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDInput` = p4.`ID`
 WHERE  (c.`CompanyProjectDetailCCID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyProjectDetailID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyProjectID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ProjectStatusID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailcc` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetails` p1 ON c.`DetailID` = p1.`ID`
  LEFT JOIN `companyprojectdetailstatusreason` p2 ON c.`ItemReasonID` = p2.`ID`
  LEFT JOIN `companyprojectdetailstatus` p3 ON c.`ItemStatusID` = p3.`ID`
  LEFT JOIN `pricetype` p4 ON c.`PriceTypeID` = p4.`ID`
  LEFT JOIN `principal` p5 ON c.`PrincipalID` = p5.`ID`
  LEFT JOIN `barang` p6 ON c.`ProductID` = p6.`ID`
  LEFT JOIN `companyprojectstatus` p7 ON c.`ProjectStatusID` = p7.`ID`
  LEFT JOIN `quantitytype` p8 ON c.`QtTypeID` = p8.`ID`
  LEFT JOIN `satuan` p9 ON c.`SatuanID` = p9.`ID`
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DetailID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ItemReasonID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ItemStatusID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PriceTypeID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`ProjectStatusID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`QtTypeID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p9.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailccassignment` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetailcc` p1 ON c.`DetailCCID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `pricetype` p3 ON c.`PriceTypeID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `barang` p5 ON c.`ProductID` = p5.`ID`
  LEFT JOIN `quantitytype` p6 ON c.`QtTypeID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanID` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDInput` = p8.`ID`
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DetailCCID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PriceTypeID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`QtTypeID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailcomp` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetails` p1 ON c.`DetailID` = p1.`ID`
  LEFT JOIN `pricetype` p2 ON c.`PriceTypeIDComp` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`PrincipalIDComp` = p3.`ID`
  LEFT JOIN `barang` p4 ON c.`ProductIDComp` = p4.`ID`
  LEFT JOIN `quantitytype` p5 ON c.`QtTypeIDComp` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`SatuanIDComp` = p6.`ID`
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DetailID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PriceTypeIDComp` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PrincipalIDComp` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ProductIDComp` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`QtTypeIDComp` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`SatuanIDComp` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailcompassignment` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetailcomp` p1 ON c.`DetailCompID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `pricetype` p3 ON c.`PriceTypeIDComp` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalIDComp` = p4.`ID`
  LEFT JOIN `barang` p5 ON c.`ProductIDComp` = p5.`ID`
  LEFT JOIN `quantitytype` p6 ON c.`QtTypeIDComp` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanIDComp` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDInput` = p8.`ID`
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DetailCompID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PriceTypeIDComp` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PrincipalIDComp` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`ProductIDComp` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`QtTypeIDComp` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`SatuanIDComp` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `companyproject` p1 ON c.`CompanyProjectID` = p1.`ID`
  LEFT JOIN `companyprojectopportunitygroup` p2 ON c.`OpportunityGroupID` = p2.`ID`
  LEFT JOIN `companyprojectstatus` p3 ON c.`ProjectStatusID` = p3.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyProjectID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`OpportunityGroupID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ProjectStatusID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailsassignment` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `companyproject` p1 ON c.`CompanyProjectID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `companyprojectopportunitygroup` p3 ON c.`OpportunityGroupID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDInput` = p4.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyProjectID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`OpportunityGroupID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailstatusassignment` c
  LEFT JOIN `companyproject` p0 ON c.`CompanyProjectID` = p0.`ID`
  LEFT JOIN `companyprojectdetailcc` p1 ON c.`DetailCCID` = p1.`ID`
  LEFT JOIN `companyprojectdetails` p2 ON c.`DetailID` = p2.`ID`
  LEFT JOIN `companyprojectdetailstatusreason` p3 ON c.`ItemReasonID` = p3.`ID`
  LEFT JOIN `companyprojectdetailstatus` p4 ON c.`ItemStatusID` = p4.`ID`
  LEFT JOIN `companyprojectstatus` p5 ON c.`ProjectStatusID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
 WHERE  (c.`CompanyProjectID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DetailCCID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ItemReasonID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ItemStatusID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`ProjectStatusID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectdetailstatusreason` c
  LEFT JOIN `companyprojectdetailstatus` p0 ON c.`StatusID` = p0.`ID`
 WHERE  (c.`StatusID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `companyprojectheaderassignment` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCP` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `companyproject` p2 ON c.`CompanyProjectID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `industry` p4 ON c.`IndustryID` = p4.`ID`
  LEFT JOIN `companyproject` p5 ON c.`ProjectID` = p5.`ID`
  LEFT JOIN `companyprojectpriority` p6 ON c.`ProjectPriority` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDSales` = p8.`ID`
 WHERE  (c.`CompanyCP` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyProjectID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`ProjectPriority` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complain` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `complainreason` p2 ON c.`ComplainReasonID` = p2.`ID`
  LEFT JOIN `complainstatus` p3 ON c.`ComplainStatusID` = p3.`ID`
  LEFT JOIN `complaintype` p4 ON c.`ComplainTypeID` = p4.`ID`
  LEFT JOIN `division` p5 ON c.`DivisionID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDSales` = p7.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainReasonID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ComplainTypeID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p7.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainassignment` c
  LEFT JOIN `complain` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complainstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`ComplainID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaindetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `complaindetailsstatus` p2 ON c.`ComplainDetailsStatusID` = p2.`ID`
  LEFT JOIN `complain` p3 ON c.`ComplainID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `satuan` p5 ON c.`SatuanComplainQuantityID` = p5.`ID`
  LEFT JOIN `quotationpack` p6 ON c.`SatuanPackingID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanUnitPriceUSD` = p7.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ComplainID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`SatuanComplainQuantityID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`SatuanPackingID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`SatuanUnitPriceUSD` IS NOT NULL AND p7.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaindetailsaction` c
  LEFT JOIN `complaindetails` p0 ON c.`ComplainDetailsID` = p0.`ID`
  LEFT JOIN `complaindetailsstatus` p1 ON c.`ComplainDetailsStatusID` = p1.`ID`
  LEFT JOIN `complain` p2 ON c.`ComplainID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`ComplainDetailsID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaindetailsactionassignment` c
  LEFT JOIN `complaindetailsaction` p0 ON c.`ComplainDetailsActionID` = p0.`ID`
  LEFT JOIN `complaindetails` p1 ON c.`ComplainDetailsID` = p1.`ID`
  LEFT JOIN `complaindetailsstatus` p2 ON c.`ComplainDetailsStatusID` = p2.`ID`
  LEFT JOIN `complain` p3 ON c.`ComplainID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserID` = p4.`ID`
 WHERE  (c.`ComplainDetailsActionID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainDetailsID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ComplainID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaindetailsassignment` c
  LEFT JOIN `complaindetails` p0 ON c.`ComplainDetailsID` = p0.`ID`
  LEFT JOIN `complaindetailsstatus` p1 ON c.`ComplainDetailsStatusID` = p1.`ID`
  LEFT JOIN `complain` p2 ON c.`ComplainID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`ComplainDetailsID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainDetailsStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitem` c
  LEFT JOIN `complainitemstatus` p0 ON c.`ComplainStatusID` = p0.`ID`
  LEFT JOIN `complainitemtype` p1 ON c.`ComplainTypeID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
 WHERE  (c.`ComplainStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainTypeID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitemassignment` c
  LEFT JOIN `complainitem` p0 ON c.`ComplainItemID` = p0.`ID`
  LEFT JOIN `complainitemstatus` p1 ON c.`ComplainItemStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`ComplainItemID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainItemStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitemdetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `company` p2 ON c.`CompanyID` = p2.`ID`
  LEFT JOIN `complaindetailsstatus` p3 ON c.`ComplainDetailStatusID` = p3.`ID`
  LEFT JOIN `complainitem` p4 ON c.`ComplainItemID` = p4.`ID`
  LEFT JOIN `division` p5 ON c.`DivisionID` = p5.`ID`
  LEFT JOIN `industry` p6 ON c.`IndustryID` = p6.`ID`
  LEFT JOIN `packing` p7 ON c.`PackingMonth` = p7.`ID`
  LEFT JOIN `packing` p8 ON c.`PackingYear` = p8.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ComplainDetailStatusID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ComplainItemID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`PackingMonth` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`PackingYear` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitemdetailsaction` c
  LEFT JOIN `complainitem` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complainitemstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`ComplainID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitemdetailsactionassignment` c
  LEFT JOIN `complainitem` p0 ON c.`ComplainItemID` = p0.`ID`
  LEFT JOIN `complainitemstatus` p1 ON c.`ComplainItemStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`ComplainItemID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainItemStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitemdetailslot` c
  LEFT JOIN `complainitemdetails` p0 ON c.`ComplainItemDetailsID` = p0.`ID`
  LEFT JOIN `complainitem` p1 ON c.`ComplainItemID` = p1.`ID`
  LEFT JOIN `packing` p2 ON c.`PackagingID` = p2.`ID`
 WHERE  (c.`ComplainItemDetailsID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainItemID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PackagingID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complainitemdetailslotassignment` c
  LEFT JOIN `complainitemdetails` p0 ON c.`ComplainItemDetailsID` = p0.`ID`
  LEFT JOIN `complainitemdetailslot` p1 ON c.`ComplainItemDetailsLotID` = p1.`ID`
  LEFT JOIN `complainitem` p2 ON c.`ComplainItemID` = p2.`ID`
  LEFT JOIN `packing` p3 ON c.`PackagingID` = p3.`ID`
 WHERE  (c.`ComplainItemDetailsID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainItemDetailsLotID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainItemID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PackagingID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaintosupplier` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `complaintosuppliertype` p2 ON c.`ComplainItemTypeID` = p2.`ID`
  LEFT JOIN `complaintosupplierstatus` p3 ON c.`ComplainStatusID` = p3.`ID`
  LEFT JOIN `complaintype` p4 ON c.`ComplainTypeID` = p4.`ID`
  LEFT JOIN `division` p5 ON c.`DivisionID` = p5.`ID`
  LEFT JOIN `industry` p6 ON c.`IndustryID` = p6.`ID`
  LEFT JOIN `packing` p7 ON c.`PackingMonth` = p7.`ID`
  LEFT JOIN `packing` p8 ON c.`PackingYear` = p8.`ID`
  LEFT JOIN `principal` p9 ON c.`PrincipalID` = p9.`ID`
  LEFT JOIN `product` p10 ON c.`ProductID` = p10.`ID`
  LEFT JOIN `users` p11 ON c.`UserIDInput` = p11.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ComplainItemTypeID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ComplainTypeID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`PackingMonth` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`PackingYear` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p9.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p10.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p11.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaintosupplier` c
  LEFT JOIN `users` p0 ON c.`UserIDSales` = p0.`ID`
 WHERE  (c.`UserIDSales` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaintosupplierassignment` c
  LEFT JOIN `complaintosupplier` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complaintosupplierstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `department` p2 ON c.`DepartmentID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
 WHERE  (c.`ComplainID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DepartmentID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaintosupplierdetailsaction` c
  LEFT JOIN `complaintosupplier` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complaintosupplierstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `department` p2 ON c.`DepartementID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
 WHERE  (c.`ComplainID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DepartementID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `complaintosupplierdetailsactionassignment` c
  LEFT JOIN `complaintosupplier` p0 ON c.`ComplainID` = p0.`ID`
  LEFT JOIN `complaintosupplierstatus` p1 ON c.`ComplainStatusID` = p1.`ID`
  LEFT JOIN `department` p2 ON c.`DepartmentID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
 WHERE  (c.`ComplainID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ComplainStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DepartmentID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `division` c
  LEFT JOIN `groupdivision` p0 ON c.`GroupDivisionID` = p0.`ID`
 WHERE  (c.`GroupDivisionID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `documentgroupdivision` c
  LEFT JOIN `documentupload` p0 ON c.`DocID` = p0.`ID`
  LEFT JOIN `groupdivision` p1 ON c.`GroupDivID` = p1.`ID`
 WHERE  (c.`DocID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`GroupDivID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `documentupload` c
  LEFT JOIN `documentcategory` p0 ON c.`DocumentCategoryID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
 WHERE  (c.`DocumentCategoryID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `documentuploadinternal` c
  LEFT JOIN `documentcategory` p0 ON c.`DocumentCategoryID` = p0.`ID`
 WHERE  (c.`DocumentCategoryID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `izin` c
  LEFT JOIN `izinstatus` p0 ON c.`IzinStatusID` = p0.`ID`
  LEFT JOIN `izintype` p1 ON c.`IzinTypeID` = p1.`ID`
  LEFT JOIN `izintypestatus` p2 ON c.`IzinTypeStatusID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDInput` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDSales` = p4.`ID`
 WHERE  (c.`IzinStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`IzinTypeID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`IzinTypeStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `izinassignment` c
  LEFT JOIN `izin` p0 ON c.`IzinID` = p0.`ID`
  LEFT JOIN `izinstatus` p1 ON c.`IzinStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`IzinID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`IzinStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `izintypestatus` c
  LEFT JOIN `izintype` p0 ON c.`IzinTypeID` = p0.`ID`
 WHERE  (c.`IzinTypeID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `labworkrequest` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `labworkrequestfeedbackstatus` p4 ON c.`LabWorkRequestFeedbackStatusID` = p4.`ID`
  LEFT JOIN `labworkrequeststatus` p5 ON c.`LabWorkRequestStatusID` = p5.`ID`
  LEFT JOIN `companyproject` p6 ON c.`ProjectID` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `users` p8 ON c.`UserIDProjectInitiator` = p8.`ID`
  LEFT JOIN `users` p9 ON c.`UserIDSales` = p9.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`LabWorkRequestFeedbackStatusID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`LabWorkRequestStatusID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`UserIDProjectInitiator` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p9.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `labworkrequestassignment` c
  LEFT JOIN `labworkrequest` p0 ON c.`LabWorkRequestID` = p0.`ID`
  LEFT JOIN `labworkrequeststatus` p1 ON c.`LabWorkRequestStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`LabWorkRequestID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`LabWorkRequestStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `labworkrequestdetails` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `labworkrequestdetailstatus` p1 ON c.`LabWorkRequestDetailStatusID` = p1.`ID`
  LEFT JOIN `labworkrequest` p2 ON c.`LabWorkRequestID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`PrincipalID` = p3.`ID`
  LEFT JOIN `companyprojectdetailcc` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `companyprojectdetailcomp` p5 ON c.`ProjectIDComp` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`SatuanIDUnitPrice` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanIDVolume` = p7.`ID`
  LEFT JOIN `type` p8 ON c.`TypeID` = p8.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`LabWorkRequestDetailStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`LabWorkRequestID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`ProjectIDComp` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`SatuanIDUnitPrice` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`SatuanIDVolume` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`TypeID` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `labworkrequestdetailsassignment` c
  LEFT JOIN `labworkrequestdetails` p0 ON c.`LabWorkRequestDetailID` = p0.`ID`
  LEFT JOIN `labworkrequestdetailstatus` p1 ON c.`LabWorkRequestDetailStatusID` = p1.`ID`
  LEFT JOIN `labworkrequest` p2 ON c.`LabWorkRequestID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`LabWorkRequestDetailID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`LabWorkRequestDetailStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`LabWorkRequestID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `labworkrequestlink` c
  LEFT JOIN `labworkrequest` p0 ON c.`LabWorkRequestID` = p0.`ID`
 WHERE  (c.`LabWorkRequestID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `lembur` c
  LEFT JOIN `lemburstatus` p0 ON c.`LemburStatusID` = p0.`ID`
  LEFT JOIN `lemburtype` p1 ON c.`LemburTypeID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDSales` = p3.`ID`
 WHERE  (c.`LemburStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`LemburTypeID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `lemburassignment` c
  LEFT JOIN `lembur` p0 ON c.`LemburID` = p0.`ID`
  LEFT JOIN `lemburstatus` p1 ON c.`LemburStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`LemburID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`LemburStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `menu` c
  LEFT JOIN `menu` p0 ON c.`ParentID` = p0.`ID`
 WHERE  (c.`ParentID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `news` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `onleave` c
  LEFT JOIN `onleavelimit` p0 ON c.`OnLeaveLimitID` = p0.`ID`
  LEFT JOIN `onleavestatus` p1 ON c.`OnLeaveStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserIDSales` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserPengganti1` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserPengganti2` = p5.`ID`
 WHERE  (c.`OnLeaveLimitID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`OnLeaveStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserPengganti1` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserPengganti2` IS NOT NULL AND p5.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `onleaveadditional` c
  LEFT JOIN `onleavelimit` p0 ON c.`OnLeaveLimitID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`OnLeaveLimitID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `onleaveadditionalassignment` c
  LEFT JOIN `onleaveadditional` p0 ON c.`OnLeaveAdditionalID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`OnLeaveAdditionalID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `onleaveassignment` c
  LEFT JOIN `onleave` p0 ON c.`OnLeaveID` = p0.`ID`
  LEFT JOIN `onleavestatus` p1 ON c.`OnLeaveStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`OnLeaveID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`OnLeaveStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `packing` c
  LEFT JOIN `satuan` p0 ON c.`SatuanID` = p0.`ID`
 WHERE  (c.`SatuanID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `potentialsales` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `potentialsaleshistory` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `potentialsales` p2 ON c.`PotentialSalesID` = p2.`ID`
  LEFT JOIN `principal` p3 ON c.`PrincipalID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserID` = p4.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PotentialSalesID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `principalcp` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
 WHERE  (c.`AddressType` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `principalcpassignment` c
  LEFT JOIN `addresstype` p0 ON c.`AddressType` = p0.`ID`
  LEFT JOIN `principalcp` p1 ON c.`PrincipalCPID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UsersID` = p3.`ID`
 WHERE  (c.`AddressType` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalCPID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UsersID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `principalfaq` c
  LEFT JOIN `principal` p0 ON c.`PrincipalID` = p0.`ID`
 WHERE  (c.`PrincipalID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `principalfaqhistory` c
  LEFT JOIN `principalfaq` p0 ON c.`PrincipalFAQID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
 WHERE  (c.`PrincipalFAQID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `printeditemfulfillment` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `product` c
  LEFT JOIN `class` p0 ON c.`ClassID` = p0.`ID`
  LEFT JOIN `packing` p1 ON c.`PackingID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
 WHERE  (c.`ClassID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PackingID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `productapplication` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`ProductID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `productcategory` c
  LEFT JOIN `category` p0 ON c.`CategoryID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`ProductID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`CategoryID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `proposedcreditceiling` c
  LEFT JOIN `creditceilingstatus` p0 ON c.`CCStatusID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `justification` p2 ON c.`JustificationID` = p2.`ID`
  LEFT JOIN `quotationpaymentterm` p3 ON c.`QuotationPaymentTermApprovedID` = p3.`ID`
  LEFT JOIN `quotationpaymentterm` p4 ON c.`QuotationPaymentTermID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
 WHERE  (c.`CCStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`JustificationID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`QuotationPaymentTermApprovedID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`QuotationPaymentTermID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `proposedcreditceilinghistory` c
  LEFT JOIN `creditceilingstatus` p0 ON c.`CCStatusID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `justification` p2 ON c.`JustificationID` = p2.`ID`
  LEFT JOIN `proposedcreditceiling` p3 ON c.`ProposedCCID` = p3.`ID`
  LEFT JOIN `quotationpaymentterm` p4 ON c.`QuotationPaymentTermApprovedID` = p4.`ID`
  LEFT JOIN `quotationpaymentterm` p5 ON c.`QuotationPaymentTermID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserID` = p6.`ID`
 WHERE  (c.`CCStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`JustificationID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ProposedCCID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`QuotationPaymentTermApprovedID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`QuotationPaymentTermID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `purchaseorder` c
  LEFT JOIN `purchaseorderstatus` p0 ON c.`PurchaseOrderStatusID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDInput` = p1.`ID`
 WHERE  (c.`PurchaseOrderStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `purchaseorderassignment` c
  LEFT JOIN `purchaseorder` p0 ON c.`PurchaseOrderID` = p0.`ID`
  LEFT JOIN `purchaseorderstatus` p1 ON c.`PurchaseOrderStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`PurchaseOrderID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PurchaseOrderStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `purchaseorderdetails` c
  LEFT JOIN `packing` p0 ON c.`PackingID` = p0.`ID`
  LEFT JOIN `purchaseorderstatus` p1 ON c.`PurchaseOrderDetailStatusID` = p1.`ID`
  LEFT JOIN `purchaseorder` p2 ON c.`PurchaseOrderID` = p2.`ID`
  LEFT JOIN `satuan` p3 ON c.`SatuanID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`SatuanOrderQtyID` = p4.`ID`
 WHERE  (c.`PackingID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PurchaseOrderDetailStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PurchaseOrderID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SatuanOrderQtyID` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `purchaseorderdetailsassignment` c
  LEFT JOIN `purchaseorderdetails` p0 ON c.`PurchaseOrderDetailID` = p0.`ID`
  LEFT JOIN `purchaseorder` p1 ON c.`PurchaseOrderID` = p1.`ID`
  LEFT JOIN `purchaseorderstatus` p2 ON c.`PurchaseOrderStatusID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`PurchaseOrderDetailID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PurchaseOrderID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PurchaseOrderStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `purchaseorderhargajual` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `quotation` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `companycp` p2 ON c.`DeliveryAddressID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `companycp` p4 ON c.`InvoiceAddressID` = p4.`ID`
  LEFT JOIN `quotationdeliverytime` p5 ON c.`QuotationDeliveryTimeID` = p5.`ID`
  LEFT JOIN `quotationfeedbackstatus` p6 ON c.`QuotationFeedbackStatusID` = p6.`ID`
  LEFT JOIN `quotationpaymentterm` p7 ON c.`QuotationPaymentTermID` = p7.`ID`
  LEFT JOIN `quotationpricedesc` p8 ON c.`QuotationPriceDescID` = p8.`ID`
  LEFT JOIN `quotationsalesterm` p9 ON c.`QuotationSalesTermID` = p9.`ID`
  LEFT JOIN `quotationstatus` p10 ON c.`QuotationStatusID` = p10.`ID`
  LEFT JOIN `quotationstockavailability` p11 ON c.`QuotationStockAvailibilityID` = p11.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DeliveryAddressID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`InvoiceAddressID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`QuotationDeliveryTimeID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`QuotationFeedbackStatusID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`QuotationPaymentTermID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`QuotationPriceDescID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`QuotationSalesTermID` IS NOT NULL AND p9.`ID` IS NULL)
    OR (c.`QuotationStatusID` IS NOT NULL AND p10.`ID` IS NULL)
    OR (c.`QuotationStockAvailibilityID` IS NOT NULL AND p11.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `quotation` c
  LEFT JOIN `quotationsubject` p0 ON c.`QuotationSubjectID` = p0.`ID`
  LEFT JOIN `quotationtitle` p1 ON c.`QuotationTitleID` = p1.`ID`
  LEFT JOIN `quotationtype` p2 ON c.`QuotationTypeID` = p2.`ID`
  LEFT JOIN `quotationvalidity` p3 ON c.`QuotationValidityID` = p3.`ID`
  LEFT JOIN `quotation` p4 ON c.`ReferenceQuotationID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
 WHERE  (c.`QuotationSubjectID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`QuotationTitleID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`QuotationTypeID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`QuotationValidityID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ReferenceQuotationID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `quotationassignment` c
  LEFT JOIN `quotation` p0 ON c.`QuotationID` = p0.`ID`
  LEFT JOIN `quotationstatus` p1 ON c.`QuotationStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`QuotationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`QuotationStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `quotationdetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `quotationitemorigin` p2 ON c.`ItemOriginID` = p2.`ID`
  LEFT JOIN `packing` p3 ON c.`PackingID` = p3.`ID`
  LEFT JOIN `companyprojectdetailcc` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `quotationdetailstatus` p5 ON c.`QuotationDetailStatusID` = p5.`ID`
  LEFT JOIN `quotation` p6 ON c.`QuotationID` = p6.`ID`
  LEFT JOIN `quotationpack` p7 ON c.`QuotationPackID` = p7.`ID`
  LEFT JOIN `satuan` p8 ON c.`SatuanID` = p8.`ID`
  LEFT JOIN `satuan` p9 ON c.`SatuanOrderQty` = p9.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ItemOriginID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`PackingID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`QuotationDetailStatusID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`QuotationID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`QuotationPackID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`SatuanOrderQty` IS NOT NULL AND p9.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `quotationdetailsassignment` c
  LEFT JOIN `quotationdetails` p0 ON c.`QuotationDetailID` = p0.`ID`
  LEFT JOIN `quotationdetailstatus` p1 ON c.`QuotationDetailStatusID` = p1.`ID`
  LEFT JOIN `quotation` p2 ON c.`QuotationID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`QuotationDetailID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`QuotationDetailStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`QuotationID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `quotationlink` c
  LEFT JOIN `quotation` p0 ON c.`QuotationID` = p0.`ID`
 WHERE  (c.`QuotationID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `reference` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `referencehistory` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `reference` p1 ON c.`ReferenceID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`ReferenceID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `relabelhistory` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `rolegadget` c
  LEFT JOIN `gadget` p0 ON c.`GadgetID` = p0.`ID`
  LEFT JOIN `role` p1 ON c.`RoleID` = p1.`ID`
 WHERE  (c.`GadgetID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`RoleID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `rolemenu` c
  LEFT JOIN `menu` p0 ON c.`MenuID` = p0.`ID`
  LEFT JOIN `role` p1 ON c.`RoleID` = p1.`ID`
 WHERE  (c.`MenuID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`RoleID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebate` c
  LEFT JOIN `quotationpaymentterm` p0 ON c.`CCPaymentTerm` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `industry` p3 ON c.`IndustryID` = p3.`ID`
  LEFT JOIN `salesrebate` p4 ON c.`ReferenceRebateID` = p4.`ID`
  LEFT JOIN `salesrebatestatus` p5 ON c.`SalesRebateStatusID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDSales` = p7.`ID`
 WHERE  (c.`CCPaymentTerm` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ReferenceRebateID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`SalesRebateStatusID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p7.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebateassignment` c
  LEFT JOIN `salesrebate` p0 ON c.`SalesRebateID` = p0.`ID`
  LEFT JOIN `salesrebatestatus` p1 ON c.`SalesRebateStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`SalesRebateID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SalesRebateStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebatedetail` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `salesrebate` p1 ON c.`SalesRebateID` = p1.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SalesRebateID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebateinvoice` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `division` p1 ON c.`DivisionID` = p1.`ID`
  LEFT JOIN `industry` p2 ON c.`IndustryID` = p2.`ID`
  LEFT JOIN `salesrebate` p3 ON c.`SalesRebateID` = p3.`ID`
  LEFT JOIN `salesrebateinvoicedetailstatus` p4 ON c.`SalesRebateInvoiceStatusID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserInput` = p5.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`SalesRebateID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SalesRebateInvoiceStatusID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserInput` IS NOT NULL AND p5.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebateinvoiceassignment` c
  LEFT JOIN `salesrebateinvoice` p0 ON c.`SalesRebateInvoiceID` = p0.`ID`
  LEFT JOIN `salesrebateinvoicedetailstatus` p1 ON c.`SalesRebateInvoiceStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDInput` = p2.`ID`
 WHERE  (c.`SalesRebateInvoiceID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SalesRebateInvoiceStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebateinvoicedetail` c
  LEFT JOIN `companycp` p0 ON c.`PaymentCPID` = p0.`ID`
  LEFT JOIN `salesrebate` p1 ON c.`SalesRebateID` = p1.`ID`
  LEFT JOIN `salesrebateinvoicedetailstatus` p2 ON c.`SalesRebateInvoiceDetailStatusID` = p2.`ID`
  LEFT JOIN `salesrebateinvoice` p3 ON c.`SalesRebateInvoiceID` = p3.`ID`
 WHERE  (c.`PaymentCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SalesRebateID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`SalesRebateInvoiceDetailStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`SalesRebateInvoiceID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `salesrebateinvoicepaymentdetail` c
  LEFT JOIN `salesrebateinvoicedetail` p0 ON c.`SalesRebateInvoiceDetailID` = p0.`ID`
 WHERE  (c.`SalesRebateInvoiceDetailID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `sampleorder` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `delivery` p2 ON c.`DeliveryID` = p2.`ID`
  LEFT JOIN `division` p3 ON c.`DivisionID` = p3.`ID`
  LEFT JOIN `industry` p4 ON c.`IndustryID` = p4.`ID`
  LEFT JOIN `location` p5 ON c.`LocationID` = p5.`ID`
  LEFT JOIN `priority` p6 ON c.`PriorityID` = p6.`ID`
  LEFT JOIN `companyproject` p7 ON c.`ProjectID` = p7.`ID`
  LEFT JOIN `sampleorder` p8 ON c.`ReferenceSOID` = p8.`ID`
  LEFT JOIN `sampleorderby` p9 ON c.`SampleOrderByID` = p9.`ID`
  LEFT JOIN `sampleorderfeedbackstatus` p10 ON c.`SampleOrderFeedbackStatusID` = p10.`ID`
  LEFT JOIN `sampleorderstatus` p11 ON c.`SampleOrderStatusID` = p11.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DeliveryID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`IndustryID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`LocationID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`PriorityID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`ReferenceSOID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`SampleOrderByID` IS NOT NULL AND p9.`ID` IS NULL)
    OR (c.`SampleOrderFeedbackStatusID` IS NOT NULL AND p10.`ID` IS NULL)
    OR (c.`SampleOrderStatusID` IS NOT NULL AND p11.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `sampleorder` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDSales` = p1.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `sampleorderassignment` c
  LEFT JOIN `sampleorder` p0 ON c.`SampleOrderID` = p0.`ID`
  LEFT JOIN `sampleorderstatus` p1 ON c.`SampleOrderStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`SampleOrderID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SampleOrderStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `sampleorderdetail` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `baranglists` p2 ON c.`BarangListID` = p2.`ID`
  LEFT JOIN `baranglists` p3 ON c.`BarangListIDRequest` = p3.`ID`
  LEFT JOIN `companyprojectdetailcc` p4 ON c.`ProjectID` = p4.`ID`
  LEFT JOIN `sampleorderdetailstatus` p5 ON c.`SampleOrderDetailStatusID` = p5.`ID`
  LEFT JOIN `sampleorder` p6 ON c.`SampleOrderID` = p6.`ID`
  LEFT JOIN `satuan` p7 ON c.`SatuanID` = p7.`ID`
  LEFT JOIN `suratjalandetails` p8 ON c.`SuratJalanDetailID` = p8.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`BarangListID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`BarangListIDRequest` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`SampleOrderDetailStatusID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`SampleOrderID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`SuratJalanDetailID` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `sampleorderdetailassignment` c
  LEFT JOIN `sampleorderdetail` p0 ON c.`SampleOrderDetailID` = p0.`ID`
  LEFT JOIN `sampleorderdetailstatus` p1 ON c.`SampleOrderDetailStatusID` = p1.`ID`
  LEFT JOIN `sampleorder` p2 ON c.`SampleOrderID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`SampleOrderDetailID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SampleOrderDetailStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`SampleOrderID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `sampleorderlink` c
  LEFT JOIN `sampleorder` p0 ON c.`SampleOrderID` = p0.`ID`
 WHERE  (c.`SampleOrderID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `samplerequestimport` c
  LEFT JOIN `delivery` p0 ON c.`DeliveryID` = p0.`ID`
  LEFT JOIN `principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `samplerequestimport` p2 ON c.`ReferenceSRID` = p2.`ID`
  LEFT JOIN `samplerequestimportfrom` p3 ON c.`RequestFromID` = p3.`ID`
  LEFT JOIN `samplerequeststatus` p4 ON c.`SampleRequestStatusID` = p4.`ID`
  LEFT JOIN `urgency` p5 ON c.`UrgencyID` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDInput` = p6.`ID`
 WHERE  (c.`DeliveryID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ReferenceSRID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`RequestFromID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SampleRequestStatusID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UrgencyID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `samplerequestimportassignment` c
  LEFT JOIN `samplerequestimport` p0 ON c.`SampleRequestImportID` = p0.`ID`
  LEFT JOIN `samplerequeststatus` p1 ON c.`SampleRequestStatusID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`SampleRequestImportID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SampleRequestStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `samplerequestimportdetail` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `baranglists` p1 ON c.`BaranglistID` = p1.`ID`
  LEFT JOIN `samplerequestimportgoodsreceipt` p2 ON c.`GoodReceiptDetailID` = p2.`ID`
  LEFT JOIN `company` p3 ON c.`ReqCompanyID` = p3.`ID`
  LEFT JOIN `samplerequeststatus` p4 ON c.`SampleRequestDetailStatusID` = p4.`ID`
  LEFT JOIN `samplerequestimport` p5 ON c.`SampleRequestImportID` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`SatuanID` = p6.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BaranglistID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`GoodReceiptDetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ReqCompanyID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SampleRequestDetailStatusID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`SampleRequestImportID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p6.`ID` IS NULL);
