Browse Source

Added more of the interface to generate csv files for GnuCash.

devel
Jonathan Rosenbaum 10 years ago
parent
commit
e59f090355
  1. 59
      Connections/database_functions.php
  2. 15
      css/transactions.css
  3. 4
      include_header.html
  4. 16
      js/transaction.js
  5. 27
      transaction_log.php

59
Connections/database_functions.php

@ -51,6 +51,12 @@ define("CSV_DIRECTORY","csv");
// mkdir csv
// chown www-data:www-data csv
// chmod 0700 csv
// Define array mapping for Accounts. Usually Assets since Income is the main type of transaction.
$gnucash_accounts = array( "Assets:Current Assets:Checking",
"Assets:Current Assets:PayPal",
"Assets:Account Receivable"
);
// other constants
define("PAGE_START_SHOP", "/start_shop.php");
@ -75,7 +81,7 @@ function generate_list($querySQL,$list_value,$list_text, $form_name, $default_va
$default_delimiter = '';
// if a form name is supplied HTML listbox code is inserted
if($form_name == "transaction_type"){
if($form_name == "transaction_type" || $form_name == "gnucash_csv_year"){
echo "<select class=\"yb_standard\" name=\"$form_name\">";
} elseif($form_name <> "none"){
echo "<select name=\"$form_name\">";
@ -98,15 +104,8 @@ function generate_list($querySQL,$list_value,$list_text, $form_name, $default_va
// if a form name is supplied HTML listbox code is inserted
if($form_name <> "none"){echo "</select>";}
}
// Function provides specific MySQL parameters to the function that generates the list box code
function list_contacts($form_name = "none", $default_value = "", $max_name_length = 20){
$querySQL = "SELECT LEFT(CONCAT(last_name, ', ', first_name, ' ',middle_initial),$max_name_length) AS full_name, contact_id, hidden FROM contacts WHERE (first_name <> '' OR last_name <> '') AND hidden <> 1 ORDER BY last_name, first_name, middle_initial";
$list_value = "contact_id";
$list_text = "full_name";
generate_list($querySQL,$list_value,$list_text,$form_name, $default_value);
}
function list_CurrentShopUsers($form_name = "none", $default_value = "", $max_name_length = 20){
$current_shop = current_shop_by_ip();
$querySQL = "SELECT full_name, shop_hours.contact_id ,hidden FROM shop_hours
@ -116,8 +115,20 @@ ORDER BY full_name;";
$list_value = "contact_id";
$list_text = "full_name";
generate_list($querySQL,$list_value,$list_text,$form_name, $default_value);
}
// #####################
// Drop down list queries - functions below could be made into one function if query, $list_value and $list_text parameters were passed
// Function provides specific MySQL parameters to the function that generates the list box code
function list_contacts($form_name = "none", $default_value = "", $max_name_length = 20){
$querySQL = "SELECT LEFT(CONCAT(last_name, ', ', first_name, ' ',middle_initial),$max_name_length) AS full_name, contact_id, hidden FROM contacts WHERE (first_name <> '' OR last_name <> '') AND hidden <> 1 ORDER BY last_name, first_name, middle_initial";
$list_value = "contact_id";
$list_text = "full_name";
generate_list($querySQL,$list_value,$list_text,$form_name, $default_value);
}
function list_coordinators($form_name = "none", $default_value = "", $max_name_length = 20){
$querySQL = "SELECT LEFT(CONCAT(last_name, ', ', first_name, ' ',middle_initial),40) AS full_name, contacts.contact_id, hidden, shop_user_role FROM contacts
LEFT JOIN (SELECT contact_id, shop_user_role, sales FROM shop_hours
@ -204,9 +215,19 @@ function list_donation_locations($form_name = "none", $default_value = "", $max_
$list_value = "contact_id";
$list_text = "full_name";
generate_list($querySQL,$list_value,$list_text,$form_name, $default_value);
}
}
// Function provides specific MySQL parameters to the function that generates the list box code
function list_distinct_shop_years($form_name = "none", $default_value = ""){
$querySQL = "SELECT DISTINCT YEAR(date) AS date FROM shops WHERE date!='NULL' ORDER BY date DESC;";
$list_value = "date";
$list_text = "date";
generate_list($querySQL,$list_value,$list_text,$form_name, $default_value);
}
// #####################
//
// Date/Time functions
function currency_format($value, $places = 2){
echo "$ ";
if(is_null($value)) echo number_format(0,$places);
@ -215,10 +236,6 @@ function currency_format($value, $places = 2){
//function to convert server time to local time. To be used by all other current date / time requests.
function local_datetime(){
// $hours_offset = UTC_TIME_OFFSET;
// $min_offset = 0;
//return time() + ( $hours_offset * 60 * 60 + $min_offset * 60 );
//offset hours; 60 mins; 60secs offset
date_default_timezone_set(TIMEZONE);
return time();
}
@ -271,6 +288,8 @@ function datetime_to_date($date_in){
$date_out = date("Y-m-d", mktime($H, $i, $s, $m,$d,$Y));
return $date_out;
}
// END Date/Time functions
//Function creates list box with times every 15 minutes for the specified number of hours
function list_15min($start_time, $start_offset_min, $form_name, $hours, $display_elapsed_hours, $default_value){
@ -364,6 +383,9 @@ function dateandtimein($date, $time){
return $time;
}
// Drop-Down lists
function list_contacts_edit_add($form_name = "contact_id", $default_value = "")
{
echo "<select name={$form_name} class='yb_standard'>\n";
@ -460,6 +482,8 @@ function list_yes_no($form_name = "list_yes_no", $default_value = 0)
echo "<option value='0'". $select_no .">No</option>";
echo "</select>\n";
}
// END Drop-Down lists
function max_shop_id(){
global $database_YBDB, $YBDB;
@ -471,7 +495,8 @@ function max_shop_id(){
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
return $row_Recordset1['shop_id'];
}
// Is there currently a shop?
function current_shop_by_ip(){
global $database_YBDB, $YBDB;
$IP = $_SERVER['REMOTE_ADDR'];

15
css/transactions.css

@ -1,7 +1,7 @@
/* sensible UI defaults for transaction views */
/* right-align labels */
td > label:not(.payment_type):not(.open_shop) {
td > label:not(.payment_type):not(.open_shop):not(.gnucash_csv) {
float: right;
padding-right: 5px;
}
@ -43,3 +43,16 @@ input[value=Save]:focus, input[value=Close]:focus {
.deposit [type='checkbox'] {
display: none;
}
/* gnucash */
[name=gnucash_csv_year] {
width: 80px;
}
#gnucash_csv_range {
width: 300px;
}
#range_slider {
padding-top: 8px;
}

4
include_header.html

@ -23,12 +23,16 @@ function resetTimer()
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>YBDB</title>
<link href="css/css_yb_standard.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.nouislider.css" rel="stylesheet" type="text/css" />
<link href="css/chosen.css" rel="stylesheet" type="text/css" />
<link href="css/transactions.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-2.1.1.js"></script>
<script src="js/transaction.js"></script>
<script src="js/jquery.mask.js"></script>
<script src="js/jquery.jeditable.js"></script>
<script src="js/jquery.nouislider.js"></script>
<script src="js/chosen.jquery.js"></script>
</head>

16
js/transaction.js

@ -145,6 +145,22 @@ $(function() {
}
});
// gnucash deposit range slider
$('#gnucash_csv_range').noUiSlider({
start: [ 20, 30 ],
range: {
'min': 10,
'max': 40
}
});
// gnucash account multi-select
$("#gnucash_csv_accounts").chosen({
placeholder_text_multiple: "Select Accounts",
width: "260px"
});
$("[name='gnucash_csv_year']").chosen();
// null or real number
function payment_result(result) {
if (result == null) {

27
transaction_log.php

@ -688,7 +688,32 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
<tr>
<td>
<br \>
<label style="font-weight:bold;" class="open_shop" for="gnucash_csv">GnuCash CSV:</label>
<label style="font-weight:bold;" class="open_shop" for="gnucash_csv">GnuCash CSV:</label>
<br \>
<?php
echo "<form method='post' name='gnucash_csv'><table><tr>";
// populate year pull-down list
echo "<td style='vertical-align:top;'><label class='gnucash_csv' for='gnucash_csv_year'>Year</label><br \>";
list_distinct_shop_years("gnucash_csv_year","");
echo "</td>";
// populate Accounts pull-down list
echo "<td style='vertical-align:top; padding-left:10px; padding-right:10px'>
<label class='gnucash_csv' for='gnucash_csv_year'>Accounts</label><br \>";
echo "<select id='gnucash_csv_accounts' class='yb_standard' multiple>";
foreach ( $gnucash_accounts as $key => $value ) {
echo "<option value='$value'>$value</option>";
}
echo "</select>";
echo "<td style='vertical-align:top; padding-left:10px; padding-right:10px; padding-bottom:10px;'>
<label class='gnucash_csv' for='gnucash_csv_range'>Deposit Range</label><br \>";
echo "<div id='range_slider'><div id='gnucash_csv_range'></div></div>";
echo "</td></tr></table></form>";
?>
</td>
</tr>
</table>

Loading…
Cancel
Save